Skip to content

Commit 6700a8a

Browse files
fix(core): add the missed implementation of AxiosError#status property; (#6573)
1 parent 7004707 commit 6700a8a

2 files changed

Lines changed: 10 additions & 2 deletions

File tree

lib/core/AxiosError.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,10 @@ function AxiosError(message, code, config, request, response) {
2727
code && (this.code = code);
2828
config && (this.config = config);
2929
request && (this.request = request);
30-
response && (this.response = response);
30+
if (response) {
31+
this.response = response;
32+
this.status = response.status ? response.status : null;
33+
}
3134
}
3235

3336
utils.inherits(AxiosError, Error, {
@@ -47,7 +50,7 @@ utils.inherits(AxiosError, Error, {
4750
// Axios
4851
config: utils.toJSONObject(this.config),
4952
code: this.code,
50-
status: this.response && this.response.status ? this.response.status : null
53+
status: this.status
5154
};
5255
}
5356
});

test/specs/core/AxiosError.spec.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,4 +48,9 @@ describe('core::AxiosError', function() {
4848
expect(AxiosError.from(error, 'ESOMETHING', { foo: 'bar' }) instanceof AxiosError).toBeTruthy();
4949
});
5050
});
51+
52+
it('should have status property when response was passed to the constructor', () => {
53+
const err = new AxiosError('test', 'foo', {}, {}, {status: 400});
54+
expect(err.status).toBe(400);
55+
});
5156
});

0 commit comments

Comments
 (0)