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
{{ message }}
Repository navigation
Throws error on :accept :json when response body is empty. #24
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.
Activity
simongray commentedon May 19, 2023
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.
alysbrooks commentedon Jul 17, 2023
I could see a case for a wrapper library like
lambdaisland/fetchcatching 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.There is one place where we catch exceptions: https://github.com/lambdaisland/fetch/blame/926fccabfebced3340548f33e41a72b159d97678/src/lambdaisland/fetch.cljs#L106. So perhaps it wouldn't be too much of a change?