2
0
mirror of https://github.com/tenrok/axios.git synced 2026-06-17 19:21:29 +03:00

fix: capture async stack only for rejections with native error objects; (#6203)

This commit is contained in:
Dmitriy Mozgovoy
2024-01-25 20:42:38 +02:00
committed by GitHub
parent 104aa3f65d
commit 1a08f90f40
2 changed files with 30 additions and 26 deletions
+14 -11
View File
@@ -39,17 +39,20 @@ class Axios {
try {
return await this._request(configOrUrl, config);
} catch (err) {
const dummy = {}
if (Error.captureStackTrace) {
Error.captureStackTrace(dummy)
} else {
dummy.stack = new Error().stack;
}
// slice off the Error: ... line
dummy.stack = dummy.stack.replace(/^.+\n/, '');
// match without the 2 top stack lines
if (!err.stack.endsWith(dummy.stack.replace(/^.+\n.+\n/, ''))) {
err.stack += '\n' + dummy.stack
if (err instanceof Error) {
let dummy;
Error.captureStackTrace ? Error.captureStackTrace(dummy = {}) : (dummy = new Error());
// slice off the Error: ... line
const stack = dummy.stack ? dummy.stack.replace(/^.+\n/, '') : '';
if (!err.stack) {
err.stack = stack;
// match without the 2 top stack lines
} else if (stack && !String(err.stack).endsWith(stack.replace(/^.+\n.+\n/, ''))) {
err.stack += '\n' + stack
}
}
throw err;