Skip to content

Commit

Permalink
Handle potential for invalid JSON
Browse files Browse the repository at this point in the history
There seems to be cases in newer `jupyter_server` versions where the
mime-type for the response is labeled as application/json but it is
actually the error message string.

Fixes the `jupyter-delete-directory` test.

* jupyter-rest-api.el (jupyter-api-url-parse-response): Catch JSON
parse errors when `url-http-response-status` >= 400 and assume what
was returned is the error message.
  • Loading branch information
nnicandro committed Oct 10, 2024
1 parent 376f679 commit 933a901
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions jupyter-rest-api.el
Original file line number Diff line number Diff line change
Expand Up @@ -171,8 +171,17 @@ If the maximum number of redirects are reached a
(let* ((json-object-type 'plist)
(json-false nil)
(resp (when (and (equal url-http-content-type "application/json")
(not (eobp)))
(json-read))))
(not (eobp)))
(if (< url-http-response-status 400)
(json-read)
;; Handle cases, for example, where status is 404
;; and the message of the error is returned
;; instead of JSON.
(let ((start (point)))
(condition-case nil
(json-read)
(error
(list :message (buffer-substring start (point-max))))))))))
(cond
((>= url-http-response-status 400)
(cl-destructuring-bind
Expand Down

0 comments on commit 933a901

Please sign in to comment.