From 7d0f2075dd45a63e2a686631cd3cd3dc5dbd5dd7 Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Sun, 26 May 2024 19:49:06 +0200 Subject: add error handling in mastodon-tl--init* (for eg domains being private) --- lisp/mastodon-tl.el | 33 +++++++++++++++++++-------------- 1 file changed, 19 insertions(+), 14 deletions(-) (limited to 'lisp') diff --git a/lisp/mastodon-tl.el b/lisp/mastodon-tl.el index b6166b1..47eafef 100644 --- a/lisp/mastodon-tl.el +++ b/lisp/mastodon-tl.el @@ -473,10 +473,12 @@ With a single prefix ARG, hide replies." (known (member domain (mastodon-http--get-json (mastodon-http--api "instance/peers"))))) - ;; TODO: refactor this: + ;; condition-case doesn't work here, so i added basic error handling to + ;; `mastodon-tl--init*' instead (if (not known) (when (y-or-n-p "Domain appears unknown to your instance. Proceed?") + ;; TODO: refactor these calls: (mastodon-tl--init buf "timelines/public" 'mastodon-tl--timeline nil params nil domain)) @@ -2855,19 +2857,22 @@ RESPONSE is the data returned from the server by `mastodon-http--process-json', with arg HEADERS a cons cell of JSON and http headers, without it just the JSON." (let ((json (if headers (car response) response))) - (if (not json) ; praying this is right here, else try "\n[]" - (message "Looks like nothing returned from endpoint: %s" endpoint) - (let* ((headers (if headers (cdr response) nil)) - (link-header (mastodon-tl--get-link-header-from-response headers))) - (with-mastodon-buffer buffer #'mastodon-mode nil - (mastodon-tl--set-buffer-spec buffer endpoint update-function - link-header update-params hide-replies) - (mastodon-tl--do-init json update-function instance)))))) - -(defun mastodon-tl--init-sync - (buffer-name endpoint update-function - &optional note-type params headers view-name binding-str) - "Initialize BUFFER-NAME with timeline targeted by ENDPOINT. + (cond ((not json) ; praying this is right here, else try "\n[]" + (message "Looks like nothing returned from endpoint: %s" endpoint)) + ((eq (caar json) 'error) + (user-error "Looks like the server bugged out: \"%s\"" (cdar json))) + (t + (let* ((headers (if headers (cdr response) nil)) + (link-header (mastodon-tl--get-link-header-from-response headers))) + (with-mastodon-buffer buffer #'mastodon-mode nil + (mastodon-tl--set-buffer-spec buffer endpoint update-function + link-header update-params hide-replies) + (mastodon-tl--do-init json update-function instance))))))) + + (defun mastodon-tl--init-sync + (buffer-name endpoint update-function + &optional note-type params headers view-name binding-str) + "Initialize BUFFER-NAME with timeline targeted by ENDPOINT. UPDATE-FUNCTION is used to receive more toots. Runs synchronously. Optional arg NOTE-TYPE means only get that type of notification. -- cgit v1.2.3