From 6700a8adac06942205f6a7a21421ecb36c4e0852 Mon Sep 17 00:00:00 2001 From: Dmitriy Mozgovoy Date: Fri, 23 Aug 2024 15:58:38 +0300 Subject: [PATCH] fix(core): add the missed implementation of AxiosError#status property; (#6573) --- lib/core/AxiosError.js | 7 +++++-- test/specs/core/AxiosError.spec.js | 5 +++++ 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/lib/core/AxiosError.js b/lib/core/AxiosError.js index 7141a8c..73da248 100644 --- a/lib/core/AxiosError.js +++ b/lib/core/AxiosError.js @@ -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, { @@ -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 }; } }); diff --git a/test/specs/core/AxiosError.spec.js b/test/specs/core/AxiosError.spec.js index 907cead..ba127d7 100644 --- a/test/specs/core/AxiosError.spec.js +++ b/test/specs/core/AxiosError.spec.js @@ -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); + }); });