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

TypeError: Failed to construct 'Response': Response with null body status cannot have body #116

Open
djherbis opened this issue Sep 15, 2020 · 4 comments

Comments

@djherbis
Copy link

TypeError: Failed to construct 'Response': Response with null body status cannot have body

response = new Response(userResponse.body or userResponse.text, userResponse)

Some status codes (ex. 204) require having no body set (null/undefined), however this statement falls back to what I believe is an empty string if no body is returned, causing the constructor call to fail and making it impossible to properly respond to these.

@djherbis
Copy link
Author

A null body status is a status that is 101, 204, 205, or 304.

Ref: https://fetch.spec.whatwg.org/#statuses

@djherbis
Copy link
Author

@jpillora I think this is a fairly tiny fix, would you be able to fix it or if I contribute a PR would you be able to do a release that includes it?

It should basically just be making sure we pass a null or undefined body to the Response constructor if the status is any of the given codes.

cchamberlain pushed a commit to cchamberlain/xhook that referenced this issue Nov 6, 2020
- Null body is now used for status codes 101, 204, 205, and 304.
- See jpillora#116 (comment)
@cchamberlain
Copy link

This issue is causing runtime errors in our project so I forked xhook and made the necessary fixes and submitted PR. We will be pointing to the fork until this change is merged / published.

@jpillora
Copy link
Owner

jpillora commented Nov 6, 2020 via email

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

No branches or pull requests

3 participants