Skip to content

Commit 43b5bc5

Browse files
committed
fix: add the missed implementation of UnError#status property, axios#6573
1 parent 025cd49 commit 43b5bc5

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

packages/core/src/core/UnError.test.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,4 +69,9 @@ describe('core::UnError', () => {
6969
).toBeTruthy();
7070
});
7171
});
72+
73+
it('should have status property when response was passed to the constructor', () => {
74+
const err = new UnError('test', 'foo', {}, {}, { status: 400 });
75+
expect(err.status).toBe(400);
76+
});
7277
});

packages/core/src/core/UnError.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,10 @@ export class UnError<T = UnData, D = UnData> extends Error {
4242
this.code = code;
4343
this.config = config;
4444
this.task = task;
45-
this.response = response;
45+
if (response) {
46+
this.response = response;
47+
this.status = response.status ?? undefined;
48+
}
4649

4750
this.isUnError = true;
4851
}
@@ -64,7 +67,7 @@ export class UnError<T = UnData, D = UnData> extends Error {
6467
stack: this.stack,
6568
config: this.config,
6669
code: this.code,
67-
status: this.response?.status,
70+
status: this.status,
6871
} as {
6972
name: string;
7073
message?: string;

0 commit comments

Comments
 (0)