Improve axios stack traces
See original GitHub issueCurrently, 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?
Issue Analytics
- State:
- Created 4 years ago
- Reactions:116
- Comments:23 (3 by maintainers)
Top Results From Across the Web
axios-better-stacktrace - npm
Axios plugin that provides better stack traces for axios errors. Check this axios issue for more details.
Read more >Improving axios errors with useful stack traces - Rafael Almeida
Axios has some issues with errors and stack traces, here's how you can fix it yourself.
Read more >axios-better-stacktrace - npm package - Snyk
Axios plugin that provides better stack traces for axios errors. Visit Snyk Advisor to see a full health score report for axios-better-stacktrace, including ......
Read more >Axios handling errors - Stack Overflow
What I pretend is to handle all errors in Request. js and only call the request function from anywhere without having to use...
Read more >Developers - Improve axios stack traces - - Bountysource
Currently, if you use axios with async / await, you get a stack trace like this: Request failed with status code 500 at...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
Top Related Hashnode Post
No results found
Top GitHub Comments
Hi @jasonsaayman, I see this issue brings lots of headaches and a bad developer experience to those who fall into these scenarios without any knowledge about the need of such interceptor.
I don’t think that’s the best solution and imho, it degrades Axios as a good library for production-ready applications.
A fix should be as easy as implementing something like
https://github.com/axios/axios/blob/5bc9ea24dda14e74def0b8ae9cdb3fa1a0c77773/lib/core/createError.js#L16-L17
to
Yes, it MAY degrade performance (imo its negligible) for failing requests, but we all know this is better than having no input for proper debugging.
I can open a PR with this and discuss the approach if you want.
This makes it super hard to debug bad responses from other servers when you are making lots of calls.