2
0
mirror of https://github.com/tenrok/axios.git synced 2026-06-08 17:22:34 +03:00

fix: wrap errors to improve async stack trace (#5987)

This commit is contained in:
Ilya Priven
2024-01-24 17:21:12 -05:00
committed by GitHub
parent 6d4c421ee1
commit 123f354b92
2 changed files with 91 additions and 8 deletions
+22 -1
View File
@@ -35,7 +35,28 @@ class Axios {
*
* @returns {Promise} The Promise to be fulfilled
*/
request(configOrUrl, config) {
async request(configOrUrl, config) {
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
}
throw err;
}
}
_request(configOrUrl, config) {
/*eslint no-param-reassign:0*/
// Allow for axios('example/url'[, config]) a la fetch API
if (typeof configOrUrl === 'string') {