branch: elpa/mastodon
commit 7988d26e291e316ce5613656286c7c39381eb609
Author: marty hiatt <martianhia...@disroot.org>
Commit: marty hiatt <martianhia...@disroot.org>

    client: add check to client--fetch.
    
    if the value of `mastodon-instance-url` is incorrect,
    `mastodon-client--register` may just return nil, such that --fetch will
    error at the with-current-buffer call.
---
 lisp/mastodon-client.el | 22 +++++++++++++---------
 1 file changed, 13 insertions(+), 9 deletions(-)

diff --git a/lisp/mastodon-client.el b/lisp/mastodon-client.el
index ea88835728..4895e84363 100644
--- a/lisp/mastodon-client.el
+++ b/lisp/mastodon-client.el
@@ -75,15 +75,19 @@
 
 (defun mastodon-client--fetch ()
   "Return JSON from `mastodon-client--register' call."
-  (with-current-buffer (mastodon-client--register)
-    (goto-char (point-min))
-    (re-search-forward "^$" nil 'move)
-    (let ((json-object-type 'plist)
-          (json-key-type 'keyword)
-          (json-array-type 'vector)
-          (json-string
-           (buffer-substring-no-properties (point) (point-max))))
-      (json-read-from-string json-string))))
+  (let ((buf (mastodon-client--register)))
+    (if (not buf)
+        (user-error "Client registration failed.\
+ Is `mastodon-instance-url' correct?")
+      (with-current-buffer buf
+        (goto-char (point-min))
+        (re-search-forward "^$" nil 'move)
+        (let ((json-object-type 'plist)
+              (json-key-type 'keyword)
+              (json-array-type 'vector)
+              (json-string
+               (buffer-substring-no-properties (point) (point-max))))
+          (json-read-from-string json-string))))))
 
 (defun mastodon-client--token-file ()
   "Return `mastodon-client--token-file'."

Reply via email to