Skip to content

Commit d951906

Browse files
authored
Use response.ok (#8)
Use response.ok
1 parent 38067b4 commit d951906

File tree

2 files changed

+2
-6
lines changed

2 files changed

+2
-6
lines changed

src/index.js

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -119,10 +119,6 @@ export default (function create(defaults) {
119119
return overrides;
120120
}
121121

122-
function isOk(status) {
123-
return (status/100|0) === 2;
124-
}
125-
126122
/**
127123
* Issues a request.
128124
* @public
@@ -181,7 +177,7 @@ export default (function create(defaults) {
181177
for (i in res) {
182178
if (typeof res[i] != 'function') response[i] = res[i];
183179
}
184-
if (!(options.validateStatus || isOk)(res.status)) {
180+
if (!(options.validateStatus ? options.validateStatus(res.status) : res.ok)) {
185181
return Promise.reject(res);
186182
}
187183
const withData = options.responseType === 'stream'

test/index.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ describe('redaxios', () => {
5353
it('should issue POST requests', async () => {
5454
const oldFetch = window.fetch;
5555
try {
56-
window.fetch = jasmine.createSpy('fetch').and.returnValue(Promise.resolve({ status: 200, text: () => Promise.resolve('yep') }));
56+
window.fetch = jasmine.createSpy('fetch').and.returnValue(Promise.resolve({ ok: true, status: 200, text: () => Promise.resolve('yep') }));
5757
const req = axios.post('/foo', {
5858
hello: 'world'
5959
});

0 commit comments

Comments
 (0)