redux-saga-thunk icon indicating copy to clipboard operation
redux-saga-thunk copied to clipboard

Header 200, empty body = Unexpected end of JSON input

Open Geczy opened this issue 7 years ago • 3 comments

middleware.js:22 Uncaught (in promise) SyntaxError: Unexpected end of JSON input

Even though the request passed and received a 200 header code. The body is empty, though, and this makes an error in redux-saga-thunk

Geczy avatar Jul 07 '17 19:07 Geczy

More info on this, appears to come as a result of redux api always assuming a response is json

https://github.com/diegohaz/arc/blob/redux/src/services/api/index.js#L16

i can submit a PR later

Geczy avatar Jul 08 '17 16:07 Geczy

API should really be returning a 204 in that instance ;) but yes, I have this same issue with vanilla fetch when you encounter an empty 200

anthonyhumphreys avatar May 27 '18 12:05 anthonyhumphreys

If anyone else encounters this, I’ve edited my version of that line to read:

export const parseJSON = response => {
  if (response.status == 204) return {}
  return response.json()
}

EricWVGG avatar Feb 21 '19 02:02 EricWVGG