fix(AxiosError): preserve original stack trace when wrapping errors (#6670) #7157
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
This PR addresses issue #6670, where
AxiosError.from()overwrote the original error’s stack trace. As a result, only the AxiosError internal stack appears in error logs (e.g. in Sentry), which obscures the root cause (DNS errors, timeouts, etc.)Changes
error.stackbefore callingAxiosError.call(...)Caused by:sectiontest/specs/core/AxiosError.spec.jsthat asserts the new stack trace contains the original error messageExample Before & After
Before :
AxiosError: Network Error
at AxiosError.from (AxiosError.js:…)
After :
AxiosError: Network Error
at AxiosError.from (AxiosError.js:…)
Caused by: Error: getaddrinfo ENOTFOUND example.com
at GetAddrInfoReqWrap.onlookupall (node:dns:…)
Impact & Backward Compatibility
No public API changes. This only enhances error diagnostics, so existing code consuming
AxiosErrorcontinues to work.This change helps debugging and observability (e.g. in error-tracking services) without altering behavior.
Testing & CI
Thanks for reviewing this change and improving diagnostics for the community!
fixes #6670