From dc33073b2da99375e1b77580f15575db78a405ac Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Fri, 27 Jan 2023 23:02:48 +0100 Subject: http--process-response: display response as error if not json still need to handle possible html. --- lisp/mastodon-http.el | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) (limited to 'lisp') diff --git a/lisp/mastodon-http.el b/lisp/mastodon-http.el index 3cc5511..88bc9c6 100644 --- a/lisp/mastodon-http.el +++ b/lisp/mastodon-http.el @@ -204,8 +204,18 @@ Callback to `mastodon-http--get-response-async', usually (buffer-substring-no-properties (point) (point-max)) 'utf-8))) (kill-buffer) - (unless (or (string-empty-p json-string) (null json-string)) - `(,(json-read-from-string json-string) . ,headers))))) + ;; (unless (or (string-empty-p json-string) (null json-string)) + (cond ((or (string-empty-p json-string) (null json-string)) + nil) + ;; if we don't have json, maybe we have a plain string error + ;; message (misskey works like this for instance, but there are + ;; probably less dunce ways to do this): + ;; FIXME: friendica at least sends plain html if endpoint not found. + ((not (or (string-prefix-p "\n{" json-string) + (string-prefix-p "\n[" json-string))) + (error "%s" json-string)) + (t + `(,(json-read-from-string json-string) . ,headers)))))) (defun mastodon-http--process-headers () "Return an alist of http response headers." -- cgit v1.2.3