Skip to content

AxiosError does not include stack trace (stack property) #4713

@asselin

Description

@asselin

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!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions