Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Comments

Changes in Response Class contructor for status range and null body status check#1706

Open
asingh04 wants to merge 2 commits intonode-fetch:mainfrom
asingh04:response-class-status-code-fix
Open

Changes in Response Class contructor for status range and null body status check#1706
asingh04 wants to merge 2 commits intonode-fetch:mainfrom
asingh04:response-class-status-code-fix

Conversation

@asingh04
Copy link

@asingh04asingh04 commentedJan 25, 2023
edited
Loading

Purpose

#1685

Changes

The validation around the input status and the validation for the null body status(204) has been added.

Additional information

  • when runningnpm lint i found an pre-existing error in the@types/index.test-d.ts file, where aResponse instance was being constructed with no purpose, so i removed it
  • also added a new npm script inpackage.json as"fix:lint": "xo --fix" so that trivial linting errors can be fixed automatically.
  • When creating a error response throughResponse.error method, the default status code was0 but this will no longer be allowed due to to validation checks, so a new value400 will be used as default status code.

  • I updated readme
  • I added unit test(s)

yks-ny reacted with thumbs up emojiyks-ny reacted with rocket emoji
super(body, options);

// eslint-disable-next-line no-eq-null, eqeqeq, no-negated-condition
const status = options.status != null ? options.status : 200;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

this check with coersion has covered the caseoptions.status !== undefined, so you can simply do
const status = options.status != null ? validateStatusValue(options.status) : 200;
but I'm not fussed, happy with either. :)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

@jazelly in this code

conststatus=options.status!=null ?validateStatusValue(options.status) :200;

if thestatus is undefined( when the client/application hasnt prvovided the value), the default value200 should be assumed, but the functionvalidateStatusValue will be throwing an error. That's why added the check forundefined as well.

yks-ny reacted with thumbs up emoji

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Yes, but notice it's a!=. Whenoptions.status isundefined,options.status != null is falsy, and will set a default 200 to the status.

yks-ny reacted with rocket emoji
static error() {
const response = new Response(null, {status: 0, statusText: ''});
// default error status code = 400
const response = new Response(null, {status: 400, statusText: ''});

This comment was marked as outdated.

const headers = new Headers(options.headers);

if (body !== null && !headers.has('Content-Type')) {
if (status === 204 && typeof body !== 'undefined' && body !== null) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

I think we also need205 and304, as perthe standard

asingh04 reacted with thumbs up emoji
Co-authored-by: Jason Zhang <xzha4350@gmail.com>
@asingh04
Copy link
Author

Hi@jazelly i will be re-working on this PR as I have mis-implemented theResponse class andstatus property which does not match with theResponse class available in the browsers

jazelly reacted with thumbs up emoji

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

1 more reviewer

@jazellyjazellyjazelly left review comments

Reviewers whose approvals may not affect merge requirements

At least 1 approving review is required to merge this pull request.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

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

2 participants

@asingh04@jazelly

[8]ページ先頭

©2009-2026 Movatter.jp