Skip to content

Commit

Permalink
fix(core): add the missed implementation of AxiosError#status propert…
Browse files Browse the repository at this point in the history
…y; (#6573)
  • Loading branch information
DigitalBrainJS authored Aug 23, 2024
1 parent 7004707 commit 6700a8a
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
7 changes: 5 additions & 2 deletions lib/core/AxiosError.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,10 @@ function AxiosError(message, code, config, request, response) {
code && (this.code = code);
config && (this.config = config);
request && (this.request = request);
response && (this.response = response);
if (response) {
this.response = response;
this.status = response.status ? response.status : null;
}
}

utils.inherits(AxiosError, Error, {
Expand All @@ -47,7 +50,7 @@ utils.inherits(AxiosError, Error, {
// Axios
config: utils.toJSONObject(this.config),
code: this.code,
status: this.response && this.response.status ? this.response.status : null
status: this.status
};
}
});
Expand Down
5 changes: 5 additions & 0 deletions test/specs/core/AxiosError.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,9 @@ describe('core::AxiosError', function() {
expect(AxiosError.from(error, 'ESOMETHING', { foo: 'bar' }) instanceof AxiosError).toBeTruthy();
});
});

it('should have status property when response was passed to the constructor', () => {
const err = new AxiosError('test', 'foo', {}, {}, {status: 400});
expect(err.status).toBe(400);
});
});

0 comments on commit 6700a8a

Please sign in to comment.