You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When you specify an :accept :json header, lambdaisland/fetch will attempt to automatically decode the response body using response.json(). However this will fail and raise an error if the response body is empty (ie JSON.parse('')).
This is sadly expected behaviour when using JS Fetch: whatwg/fetch#113
Why WHATWG didn't think this would be an issue by when they designed the API, I really have no idea. Returning 204 or 404 with no body is a common situation on the Internet and I don't think the server isn't supposed to make up imaginary content just because the client is requesting a specific content-type.
I guess this library could have a fix for us using it.
I could see a case for a wrapper library like lambdaisland/fetch catching the error or even rethrowing a more reasonable one, but that would be an expansion to this library's scope. The code would be trivial, but semantically it would be a bit of a shift.
When you specify an
:accept :json
header,lambdaisland/fetch
will attempt to automatically decode the response body usingresponse.json()
. However this will fail and raise an error if the response body is empty (ieJSON.parse('')
).fetch/src/lambdaisland/fetch.cljs
Lines 66 to 67 in 246d561
The code should probably check if the body is empty first.
The text was updated successfully, but these errors were encountered: