aboutsummaryrefslogtreecommitdiff
path: root/stack-core.el
diff options
context:
space:
mode:
authorSean Allred <code@seanallred.com>2014-10-31 01:49:28 -0400
committerSean Allred <code@seanallred.com>2014-10-31 01:49:28 -0400
commit4a5119c3ace6391132d66258c0e771b69cb3ff8c (patch)
tree1d848cd03e14b37100c4d172286fca9cc8164ef9 /stack-core.el
parentff12289c437f3c3589b63186d5090bd7e81e8649 (diff)
Give more informative message after json error
Diffstat (limited to 'stack-core.el')
-rw-r--r--stack-core.el49
1 files changed, 28 insertions, 21 deletions
diff --git a/stack-core.el b/stack-core.el
index 294bce1..f7381cb 100644
--- a/stack-core.el
+++ b/stack-core.el
@@ -146,27 +146,34 @@ with the given KEYWORD-ARGUMENTS."
optional KEYWORD-ARGUMENTS. If no KEYWORD-ARGUMENTS are given,
`stack-core-default-keyword-arguments-alist' is used. Return the
entire response as a complex alist."
- (let ((response
- (json-read-from-string
- (let ((call (stack-core-build-request
- method
- (cons `(filter . ,(cond
- (filter filter)
- ((boundp 'stack-filter)
- stack-filter)))
- (if keyword-arguments keyword-arguments
- (stack-core-get-default-keyword-arguments
- method)))))
- (url-automatic-caching stack-core-cache-requests))
- ;; TODO: url-retrieve-synchronously can return nil if the call is
- ;; unsuccessful should handle this case
- (stack-message "Request: %s" call)
- (with-current-buffer (url-retrieve-synchronously call)
- (goto-char (point-min))
- (if (not (search-forward "\n\n" nil t))
- (error "Response corrupted")
- (delete-region (point-min) (point))
- (buffer-string)))))))
+ (let ((api-response
+ (let ((call
+ (stack-core-build-request
+ method
+ (cons `(filter . ,(cond
+ (filter filter)
+ ((boundp 'stack-filter)
+ stack-filter)))
+ (if keyword-arguments keyword-arguments
+ (stack-core-get-default-keyword-arguments
+ method)))))
+ (url-automatic-caching stack-core-cache-requests))
+ ;; TODO: url-retrieve-synchronously can return nil if the call is
+ ;; unsuccessful should handle this case
+ (stack-message "Request: %s" call)
+ (with-current-buffer (url-retrieve-synchronously call)
+ (goto-char (point-min))
+ (if (not (search-forward "\n\n" nil t))
+ (error "Response corrupted")
+ (delete-region (point-min) (point))
+ (buffer-string)))))
+ (response
+ (with-demoted-errors "JSON Error: %s"
+ (json-read-from-string api-response))))
+ (unless response
+ (stack-message "Printing response as message")
+ (message response)
+ (error "Response could not be read by json-read-string"))
(when (assoc 'error_id response)
(error "Request failed: (%s) [%i %s] %s"
method