mirror of
https://github.com/tenrok/axios.git
synced 2026-06-20 20:00:40 +03:00
Updating AxiosError to include stack trace (#4624)
Related to discussions here https://github.com/axios/axios/issues/2387 Attempt to capture the stack trace at the time the error is created in order to maintain context about where the error originates from. Co-authored-by: Jay <jasonsaayman@gmail.com>
This commit is contained in:
@@ -14,6 +14,11 @@ var utils = require('../utils');
|
|||||||
*/
|
*/
|
||||||
function AxiosError(message, code, config, request, response) {
|
function AxiosError(message, code, config, request, response) {
|
||||||
Error.call(this);
|
Error.call(this);
|
||||||
|
|
||||||
|
if (Error.captureStackTrace) {
|
||||||
|
Error.captureStackTrace(this);
|
||||||
|
}
|
||||||
|
|
||||||
this.message = message;
|
this.message = message;
|
||||||
this.name = 'AxiosError';
|
this.name = 'AxiosError';
|
||||||
code && (this.code = code);
|
code && (this.code = code);
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
var AxiosError = require('../../../lib/core/AxiosError');
|
var AxiosError = require('../../../lib/core/AxiosError');
|
||||||
|
|
||||||
describe('core::AxiosError', function() {
|
describe('core::AxiosError', function() {
|
||||||
it('should create an Error with message, config, code, request, response and isAxiosError', function() {
|
it('should create an Error with message, config, code, request, response, stack and isAxiosError', function() {
|
||||||
var request = { path: '/foo' };
|
var request = { path: '/foo' };
|
||||||
var response = { status: 200, data: { foo: 'bar' } };
|
var response = { status: 200, data: { foo: 'bar' } };
|
||||||
var error = new AxiosError('Boom!', 'ESOMETHING', { foo: 'bar' }, request, response);
|
var error = new AxiosError('Boom!', 'ESOMETHING', { foo: 'bar' }, request, response);
|
||||||
@@ -12,6 +12,7 @@ describe('core::AxiosError', function() {
|
|||||||
expect(error.request).toBe(request);
|
expect(error.request).toBe(request);
|
||||||
expect(error.response).toBe(response);
|
expect(error.response).toBe(response);
|
||||||
expect(error.isAxiosError).toBe(true);
|
expect(error.isAxiosError).toBe(true);
|
||||||
|
expect(error.stack).toBeDefined();
|
||||||
});
|
});
|
||||||
it('should create an Error that can be serialized to JSON', function() {
|
it('should create an Error that can be serialized to JSON', function() {
|
||||||
// Attempting to serialize request and response results in
|
// Attempting to serialize request and response results in
|
||||||
|
|||||||
Reference in New Issue
Block a user