Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updating AxiosError to include stack trace #4624

Merged
merged 3 commits into from May 3, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 5 additions & 0 deletions lib/core/AxiosError.js
Expand Up @@ -14,6 +14,11 @@ var utils = require('../utils');
*/
function AxiosError(message, code, config, request, response) {
Error.call(this);

if (Error.captureStackTrace) {
Error.captureStackTrace(this);
}

this.message = message;
this.name = 'AxiosError';
code && (this.code = code);
Expand Down
3 changes: 2 additions & 1 deletion test/specs/core/AxiosError.spec.js
@@ -1,7 +1,7 @@
var AxiosError = require('../../../lib/core/AxiosError');

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 response = { status: 200, data: { foo: 'bar' } };
var error = new AxiosError('Boom!', 'ESOMETHING', { foo: 'bar' }, request, response);
Expand All @@ -12,6 +12,7 @@ describe('core::AxiosError', function() {
expect(error.request).toBe(request);
expect(error.response).toBe(response);
expect(error.isAxiosError).toBe(true);
expect(error.stack).toBeDefined();
});
it('should create an Error that can be serialized to JSON', function() {
// Attempting to serialize request and response results in
Expand Down