Skip to content

Commit

Permalink
fix: add the missed implementation of UnError#status property, axios#…
Browse files Browse the repository at this point in the history
…6573
  • Loading branch information
ModyQyW committed Sep 2, 2024
1 parent 025cd49 commit 43b5bc5
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
5 changes: 5 additions & 0 deletions packages/core/src/core/UnError.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,4 +69,9 @@ describe('core::UnError', () => {
).toBeTruthy();
});
});

it('should have status property when response was passed to the constructor', () => {
const err = new UnError('test', 'foo', {}, {}, { status: 400 });
expect(err.status).toBe(400);
});
});
7 changes: 5 additions & 2 deletions packages/core/src/core/UnError.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,10 @@ export class UnError<T = UnData, D = UnData> extends Error {
this.code = code;
this.config = config;
this.task = task;
this.response = response;
if (response) {
this.response = response;
this.status = response.status ?? undefined;
}

this.isUnError = true;
}
Expand All @@ -64,7 +67,7 @@ export class UnError<T = UnData, D = UnData> extends Error {
stack: this.stack,
config: this.config,
code: this.code,
status: this.response?.status,
status: this.status,
} as {
name: string;
message?: string;
Expand Down

0 comments on commit 43b5bc5

Please sign in to comment.