-
-
Notifications
You must be signed in to change notification settings - Fork 11.6k
AxiosError does not include stack trace (stack property) #4713
Description
Version 0.26.1 of axios created errors by calling new Error(), and then augmenting it. Doing it this way, the error object contained a stack property with the stack trace.
With version 0.27, axios creates errors as an Object, and doesn't add the stack property to them, so there's no stack trace available.
Expected behavior is that there will be a stack property with a stack trace.
The issue is that the constructor for AxiosError does Error.call(this);, but that doesn't add a stack trace property. Adding the stack trace needs to be done after that using code like:
// Use V8's native method if available, otherwise fallback
if ("captureStackTrace" in Error)
Error.captureStackTrace(this, InvalidArgumentException);
else
this.stack = (new Error()).stack;
See my stack overflow article https://stackoverflow.com/questions/464359/custom-exception-type/27724419#27724419 for more info.
I can submit a PR if you guys agree on the technique.
Thanks!