Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid body method parse errors on 204 responses #196

Merged
merged 3 commits into from
Nov 8, 2019

Conversation

sholladay
Copy link
Collaborator

@sholladay sholladay commented Nov 8, 2019

Closes #193

This PR short-circuits the .json() body method and makes it return an empty string instead of parsing the body when the response status is 204 No Content. That way we avoid throwing a parse error due to an empty body.

Note that, as of this writing, we make no attempt to read the response body to check if it is empty, rather we trust the response status code from the server.

@sindresorhus
Copy link
Owner

Can you update index.d.ts too?

@sholladay
Copy link
Collaborator Author

Should be ready to merge.

Since we decided to go with empty string, the TypeScript types don't need to be updated.

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

Successfully merging this pull request may close these issues.

Don't throw on 204 No Content when parsing response
3 participants