From 39a54a6aaf1a6f043bfe8769ef0c3484de917e7c Mon Sep 17 00:00:00 2001 From: mousebot Date: Fri, 29 Oct 2021 11:58:53 +0200 Subject: hopefully improve attachment upload error handling --- lisp/mastodon-http.el | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/lisp/mastodon-http.el b/lisp/mastodon-http.el index 4f4cc3f..b5437a3 100644 --- a/lisp/mastodon-http.el +++ b/lisp/mastodon-http.el @@ -285,15 +285,21 @@ The upload is asynchronous. On succeeding, `mastodon-toot--media-attachment-ids' (mastodon-toot--update-status-fields))))) :error (cl-function (lambda (&key error-thrown &allow-other-keys) - (message "%s" (car (last error-thrown))) - (message "%s" (type-of (car (last error-thrown)))) - (cond ((= (car (last error-thrown)) 401) - (message "Got error: %s Unauthorized: The access token is invalid" error-thrown)) - ((= (car (last error-thrown)) 422) - (message "Got error: %s Unprocessable entity: file or file type is unsupported or invalid" error-thrown)) - (t - (message "Got error: %s Shit went south" - error-thrown)))))))) + (cond + ;; handle curl errors first (eg 26, can't read file/path) + ;; because the '=' test below fails for them + ;; they have the form (error . error message 24) + ((not (proper-list-p error-thrown)) ; not dotted list + (message "Got error: %s. Shit went south." (cdr error-thrown))) + ;; handle mastodon api errors + ;; they have the form (error http 401) + ((= (car (last error-thrown)) 401) + (message "Got error: %s Unauthorized: The access token is invalid" error-thrown)) + ((= (car (last error-thrown)) 422) + (message "Got error: %s Unprocessable entity: file or file type is unsupported or invalid" error-thrown)) + (t + (message "Got error: %s Shit went south" + error-thrown)))))))) (provide 'mastodon-http) ;;; mastodon-http.el ends here -- cgit v1.2.3