diff options
author | Sean Allred <code@seanallred.com> | 2014-10-31 01:49:28 -0400 |
---|---|---|
committer | Sean Allred <code@seanallred.com> | 2014-10-31 01:49:28 -0400 |
commit | 4a5119c3ace6391132d66258c0e771b69cb3ff8c (patch) | |
tree | 1d848cd03e14b37100c4d172286fca9cc8164ef9 | |
parent | ff12289c437f3c3589b63186d5090bd7e81e8649 (diff) |
Give more informative message after json error
-rw-r--r-- | .travis.yml | 4 | ||||
-rw-r--r-- | stack-core.el | 49 |
2 files changed, 30 insertions, 23 deletions
diff --git a/.travis.yml b/.travis.yml index 51d5b5d..701ec4a 100644 --- a/.travis.yml +++ b/.travis.yml @@ -14,10 +14,10 @@ before_install: - curl -fsSkL https://gist.github.com/rejeep/7736123/raw | sh - export PATH="/home/travis/.cask/bin:$PATH" - export PATH="/home/travis/.evm/bin:$PATH" + - cask --version - cask info - - cask outdated - cask install + - $EMACS --version script: - - $EMACS --version - $EMACS -batch -L . -l ert -l tests.el -f ert-run-tests-batch-and-exit 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 |