Skip to content
This repository has been archived by the owner on Feb 6, 2018. It is now read-only.

Client fails to parse json response on 204 status using fetch #83

Closed
bedeoverend opened this issue Nov 3, 2016 · 2 comments
Closed

Comments

@bedeoverend
Copy link
Contributor

Steps to reproduce

Call a service method which returns a 204 status with no body while using the fetch connection - response.json() then fails to parse the body and throws and error.

https://jsbin.com/wacosaneqo/edit?html,console

Expected behavior

It should return a null response and throw no error

Actual behavior

Throws Error: Unexpected end of JSON input

System configuration

Operating System:
macOS Sierra

Browser Version:
Chrome 54

@daffl
Copy link
Member

daffl commented Nov 5, 2016

Good catch. You would think fetch knows about this. The fix is probably to check for a 204 status code in https://github.com/feathersjs/feathers-rest/blob/master/src/client/fetch.js#L22.

@bedeoverend
Copy link
Contributor Author

@daffl yeah I tried internally, and just adding an if (response.status === 204) at that line you've linked to does the trick. I'll make a PR with tests.

Unfortunately fetch knows and its considered expected behavior, though I get that how low level it is they didn't want to treat it any different just because it was JSON.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants