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

Add status 422 to the accepted statuses into succeeded #4

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -151,9 +151,9 @@ Instead of returning the default fetch response which contains only status and h

| Methods | Description | Returns |
| --------------- | -------------------------------------------------------------------------------------------- | ----------------- |
| succeeded | Check if status is between `200` and `300` and if there is no error. | `boolean` |
| bodyIfSucceeded | Return the body of the request if the status is between `200` and `300` else return `false`. | `body` or `false` |
| bodyOrThrow | Return the body of the request if the status is between `200` and `300` else throw a error. | `body` or throw |
| succeeded | Check if status is between `200` and `300` or `422` and if there is no error. | `boolean` |
| bodyIfSucceeded | Return the body of the request if the status is between `200` and `300` or `422` else return `false`. | `body` or `false` |
| bodyOrThrow | Return the body of the request if the status is between `200` and `300` or `422` else throw a error. | `body` or throw |
| didNetworkFail | If the network request failed, return `true` or `false` | `boolean` |
| didServerFail | Tell you if you get error from the server. | `boolean` |

Expand Down
3 changes: 2 additions & 1 deletion __tests__/response.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,10 @@ describe('Response', () => {
});

describe('succeeded', () => {
it('returns true if request status is among 200-300', () => {
it('returns true if request status is among 200-300 or 422', () => {
expect(new Response({ status: 200 }).succeeded).toBeTruthy();
expect(new Response({ status: 299 }).succeeded).toBeTruthy();
expect(new Response({ status: 422 }).succeeded).toBeTruthy();
expect(new Response({ status: 250 }).succeeded).toBeTruthy();
expect(new Response({ status: 300 }).succeeded).toBeFalsy();
});
Expand Down
5 changes: 3 additions & 2 deletions src/response.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,9 @@ export default class Response {
}

get succeeded() {
return !this.error
return (!this.error
&& this.status >= 200
&& this.status < 300;
&& this.status < 300)
|| this.status === 422;
}
}