aboutsummaryrefslogtreecommitdiff
path: root/lisp/mastodon-media.el
diff options
context:
space:
mode:
authorIan Eure <ian@retrospec.tv>2020-05-03 10:46:53 -0700
committerIan Eure <ian@retrospec.tv>2020-05-03 11:33:08 -0700
commit2a6568d3d9a7b121a4ee760eea0dfb2f91f79fb1 (patch)
tree3df8483ac5c899f860e30ba6602689b392c1de47 /lisp/mastodon-media.el
parent5095797ef32b922d2a624fa6beb970b5e9cf5ca0 (diff)
Rewrite `mastodon-auth--access-token` so it handles errors.
Currently, `mastodon-auth--access-token` unconditionally returns the value of the `:access_token` key from the response of `(mastodon-auth--get-token)`. This causes problems when there was an error getting the token, for example, if you enter the wrong password. If a token couldn’t be retrieved, the JSON looks like: (:error "invalid_grant" :error_description "The provided authorization grant is invalid, expired, revoked, does not match the redirection URI used in the authorization request, or was issued to another client.") Since there is no `:access_token` key, `mastodon-auth--access-token` returns `nil`, which results in a broken header in the next request: Authorization: Bearer Which causes the whole thing to freeze Emacs until you mash `C-g`. This commit rewrites the function to handle that case; to explicitly signal an error for *any* response that isn’t expected; to use `if-let`, which allows the temporary `token` variable to be eliminated; uses `pcase` to determine what kind of response was received; and adds ERT tests for all these cases.
Diffstat (limited to 'lisp/mastodon-media.el')
0 files changed, 0 insertions, 0 deletions