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

When initializing a response it should throw if status is not in the range 200 to 599 #1685

Open
tkrotoff opened this issue Dec 1, 2022 · 2 comments · May be fixed by #1706
Open

When initializing a response it should throw if status is not in the range 200 to 599 #1685

tkrotoff opened this issue Dec 1, 2022 · 2 comments · May be fixed by #1706

Comments

@tkrotoff
Copy link
Contributor

tkrotoff commented Dec 1, 2022

From the spec https://fetch.spec.whatwg.org/#response-class

To initialize a response, given a Response object response, ResponseInit init, and an optional body with type body, run these steps:
 1. If init["status"] is not in the range 200 to 599, inclusive, then throw a RangeError.
 2. If init["statusText"] does not match the reason-phrase token production, then throw a TypeError.
 [...]
 6. If body was given, then:
      1. If response’s status is a null body status, then throw a TypeError.
      [...]

Reproduction

new Response('body', { status: 204 }); // KO Not throwing
new Response(undefined, { status: 204 }); // Not throwing is correct here
new Response(undefined, { status: 0 }); // KO Not throwing

Expected behavior

Under Chrome 107:

new Response('body', { status: 204 });
// TypeError: Failed to construct 'Response': Response with null body status cannot have body

new Response(undefined, { status: 204 });
// No throwing

new Response(undefined, { status: 0 });
// RangeError: Failed to construct 'Response': The status provided (0) is outside the range [200, 599].

Your Environment

software version
node-fetch 3.3.0
node 18.12.1
npm 8.19.2
Operating System macOS Monterey
@asingh04
Copy link

If this issue is open and no one is working on it, i would like to work on it

@LinusU
Copy link
Member

LinusU commented Jan 25, 2023

@asingh04 PR welcome! 🙌

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

Successfully merging a pull request may close this issue.

3 participants