From 50e6752a2e472e4af4e6ab9dcbf89f3585871679 Mon Sep 17 00:00:00 2001 From: Ilya Priven Date: Thu, 28 Sep 2023 00:20:12 -0400 Subject: [PATCH] fix: propagate stack-trace across async --- lib/adapters/http.js | 7 +++++++ lib/core/AxiosError.js | 3 +++ 2 files changed, 10 insertions(+) diff --git a/lib/adapters/http.js b/lib/adapters/http.js index 201252ff85..543a724d2b 100755 --- a/lib/adapters/http.js +++ b/lib/adapters/http.js @@ -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; diff --git a/lib/core/AxiosError.js b/lib/core/AxiosError.js index 7141a8cdbf..765552b9a7 100644 --- a/lib/core/AxiosError.js +++ b/lib/core/AxiosError.js @@ -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';