mirror of
https://github.com/tenrok/axios.git
synced 2026-06-20 20:00:40 +03:00
* fix: turn AxiosError into a native error (#5394) Being an object returned by the 'Error' constructor turns something into a 'native error'. * fix: simplify code in AxiosError * fix: simplify code in AxiosError * refactor: implement AxiosError as a class * refactor: implement CanceledError as a class This turns CanceledError into a native error. * refactor: simplify AxiosError.toJSON * fix: improve error code handling in `AxiosError.from` If no error code is provided, use the code from the underlying error. * fix: set error status in `AxiosError.constructor` If a response is passed to the constructor, set the response status as a property. * fix: remove unnecessary async --------- Co-authored-by: Jay <jasonsaayman@gmail.com>
This commit is contained in:
@@ -12,4 +12,10 @@ describe('Cancel', function() {
|
||||
expect(cancel.toString()).toBe('CanceledError: Operation has been canceled.');
|
||||
});
|
||||
});
|
||||
it('should be a native error as checked by the NodeJS `isNativeError` function', function (){
|
||||
if((typeof process !== 'undefined') && (process.release.name === 'node')){
|
||||
let {isNativeError} = require('node:util/types');
|
||||
expect(isNativeError(new CanceledError("My Canceled Error"))).toBeTruthy();
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import AxiosError from '../../../lib/core/AxiosError';
|
||||
|
||||
|
||||
describe('core::AxiosError', function() {
|
||||
it('should create an Error with message, config, code, request, response, stack and isAxiosError', function() {
|
||||
const request = { path: '/foo' };
|
||||
@@ -49,6 +50,18 @@ describe('core::AxiosError', function() {
|
||||
});
|
||||
});
|
||||
|
||||
it('should be a native error as checked by the NodeJS `isNativeError` function', function (){
|
||||
if((typeof process !== 'undefined') && (process.release.name === 'node')){
|
||||
let {isNativeError} = require('node:util/types');
|
||||
expect(isNativeError(new AxiosError("My Axios Error"))).toBeTruthy();
|
||||
}
|
||||
});
|
||||
|
||||
it('should create an error using one of the static class properties as an error code', function (){
|
||||
const myError = new AxiosError("My Axios Error", AxiosError.ECONNABORTED);
|
||||
expect(myError.code).toEqual(AxiosError.ECONNABORTED);
|
||||
});
|
||||
|
||||
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);
|
||||
|
||||
Reference in New Issue
Block a user