Skip to content

Improve axios stack traces #2387

@rclmenezes

Description

@rclmenezes

Currently, if you use axios with async / await, you get a stack trace like this:

Request failed with status code 500
    at createError (/Users/rmenezes/code/seedfi/web/node_modules/axios/lib/core/createError.js:16:15)
    at settle (/Users/rmenezes/code/seedfi/web/node_modules/axios/lib/core/settle.js:17:12)
    at IncomingMessage.handleStreamEnd (/Users/rmenezes/code/seedfi/web/node_modules/axios/lib/adapters/http.js:237:11)
    at IncomingMessage.emit (events.js:208:15)
    at IncomingMessage.EventEmitter.emit (domain.js:471:20)
    at endReadableNT (_stream_readable.js:1154:12)
    at processTicksAndRejections (internal/process/task_queues.js:77:11

It doesn't show you much about what called Axios., which makes debugging quite difficult!

This is because settle calls createError:
https://github.com/axios/axios/blob/master/lib/core/settle.js#L12-L24

Which creates a new error with a brand new stack trace:
https://github.com/axios/axios/blob/master/lib/core/createError.js#L15-L18

Perhaps we can fix this by creating an error before the request goes out and stitching it to the new error's stack trace?

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