question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Improve axios stack traces

See original GitHub issue

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?

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:116
  • Comments:23 (3 by maintainers)

github_iconTop GitHub Comments

37reactions
Frondorcommented, Aug 31, 2021

Please use the interceptor approach mentioned above, we will address this in the future however currently an interceptor is the most appropriate solution.

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

var axiosError = enhanceError(new Error(message), config, code, request, response);
if (Error.captureStackTrace) Error.captureStackTrace(axiosError, createError);
return axiosError;

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.

34reactions
jmiccocommented, Oct 19, 2019

This makes it super hard to debug bad responses from other servers when you are making lots of calls.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Hashnode Post

No results found