aboutsummaryrefslogtreecommitdiff
path: root/lisp/mastodon-auth.el
diff options
context:
space:
mode:
Diffstat (limited to 'lisp/mastodon-auth.el')
-rw-r--r--lisp/mastodon-auth.el23
1 files changed, 16 insertions, 7 deletions
diff --git a/lisp/mastodon-auth.el b/lisp/mastodon-auth.el
index 231bb70..cfe89b5 100644
--- a/lisp/mastodon-auth.el
+++ b/lisp/mastodon-auth.el
@@ -124,13 +124,22 @@ Reads and/or stores secres in `MASTODON-AUTH-SOURCE-FILE'."
"Return the access token to use with the current `mastodon-instance-url'.
Generate token and set if none known yet."
- (let ((token
- (cdr (assoc mastodon-instance-url mastodon-auth--token-alist))))
- (unless token
- (let ((json (mastodon-auth--get-token)))
- (setq token (plist-get json :access_token))
- (push (cons mastodon-instance-url token) mastodon-auth--token-alist)))
- token))
+ (if-let ((token (cdr (assoc mastodon-instance-url mastodon-auth--token-alist))))
+ token
+
+ (mastodon-auth--handle-token-response (mastodon-auth--get-token))))
+
+(defun mastodon-auth--handle-token-response (response)
+ (pcase response
+ ((and (let token (plist-get response :access_token))
+ (guard token))
+ (cdar (push (cons mastodon-instance-url token)
+ mastodon-auth--token-alist)))
+
+ (`(:error ,class :error_description ,error)
+ (error "mastodon-auth--access-token: %s: %s" class error))
+
+ (_ (error "Unknown response from mastodon-auth--get-token!"))))
(defun mastodon-auth--get-account-name ()
"Request user credentials and return an account name."