Skip to content

Commit

Permalink
fix: propagate stack-trace across async
Browse files Browse the repository at this point in the history
  • Loading branch information
ikonst committed Sep 28, 2023
1 parent 88fb52b commit 50e6752
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
7 changes: 7 additions & 0 deletions lib/adapters/http.js
Expand Up @@ -434,6 +434,13 @@ export default isHttpAdapterSupported && function httpAdapter(config) {
options.insecureHTTPParser = config.insecureHTTPParser;
}

// Propagate stack-trace across async boundary
if (Error.captureStackTrace) {
Error.captureStackTrace(config);
} else {
config.stack = (new Error()).stack;
}

// Create the request
req = transport.request(options, function handleResponse(res) {
if (req.destroyed) return;
Expand Down
3 changes: 3 additions & 0 deletions lib/core/AxiosError.js
Expand Up @@ -21,6 +21,9 @@ function AxiosError(message, code, config, request, response) {
} else {
this.stack = (new Error()).stack;
}
if (config.stack) {
this.stack += config.stack;
}

this.message = message;
this.name = 'AxiosError';
Expand Down

0 comments on commit 50e6752

Please sign in to comment.