Skip to content

Commit 933a901

Browse files
committed
Handle potential for invalid JSON
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.
1 parent 376f679 commit 933a901

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

jupyter-rest-api.el

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -171,8 +171,17 @@ If the maximum number of redirects are reached a
171171
(let* ((json-object-type 'plist)
172172
(json-false nil)
173173
(resp (when (and (equal url-http-content-type "application/json")
174-
(not (eobp)))
175-
(json-read))))
174+
(not (eobp)))
175+
(if (< url-http-response-status 400)
176+
(json-read)
177+
;; Handle cases, for example, where status is 404
178+
;; and the message of the error is returned
179+
;; instead of JSON.
180+
(let ((start (point)))
181+
(condition-case nil
182+
(json-read)
183+
(error
184+
(list :message (buffer-substring start (point-max))))))))))
176185
(cond
177186
((>= url-http-response-status 400)
178187
(cl-destructuring-bind

0 commit comments

Comments
 (0)