axios
axios copied to clipboard
http error should have stacktrace at line of invoking axios
Is your feature request related to a problem? Please describe.
Related to the issue #2387 and I don't think the stacktrace is improved.
Describe the solution you'd like
When there is a http error, I'm expecting the stacktrace to point to the application code of where we invoked the axios call that ended causing the http error, not a stacktrace within a 3rd party library.
Additional context
index.js
const axios = require("axios");
const main = async () => {
await axios("http://localhost:9999");
};
main()
.catch((err) => console.error(JSON.stringify(err)))
.finally(() => console.log("end of main"));
package.json
{
"name": "axios-http-error-stack",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"start": "node index.js"
},
"author": "",
"license": "ISC",
"dependencies": {
"axios": "^1.0.0"
}
}
stack
Error: connect ECONNREFUSED 127.0.0.1:9999
at Function.AxiosError.from (/Users/longility/Repos/axios-http-error-stack/node_modules/axios/dist/node/axios.cjs:725:14)
at RedirectableRequest.handleRequestError (/Users/longility/Repos/axios-http-error-stack/node_modules/axios/dist/node/axios.cjs:2460:25)
at RedirectableRequest.emit (node:events:526:28)
at ClientRequest.eventHandlers.<computed> (/Users/longility/Repos/axios-http-error-stack/node_modules/follow-redirects/index.js:14:24)
at ClientRequest.emit (node:events:526:28)
at Socket.socketErrorListener (node:_http_client:442:9)
at Socket.emit (node:events:526:28)
at emitErrorNT (node:internal/streams/destroy:157:8)
at emitErrorCloseNT (node:internal/streams/destroy:122:3)
at processTicksAndRejections (node:internal/process/task_queues:83:21)
Any improvements for this? Stack trace of third party library is not useful.
Sorry to add a "+1" here, but this is very important, IMO. I've dozens of axios calls across my app, and if the remote server returns anything but a 200, I see an error in my logs, I get an error in my error service, but I have no idea where it occurred. Right now, I can catch the error, and throw a new one, but then I lose some of the fidelity data from the HTTP response object. This was supposed to have been fixed in v1, so at first I thought I was doing something wrong, but I'm glad I found this issue to know that it wasn't just me. I also tried the axios-better-stacktrace
package and even that did not work for me. This was supposed to be fixed multiple times, and is such a fundamental feature of this type of system library.
The same problem with me of version 1.4.0
Looks like it was fixed in https://github.com/axios/axios/pull/5987
@fredymorales I tried but not solved in v1.6.8
Stacktrace on v1.4.0
Non-fatal Exception: io.invertase.firebase.crashlytics.a: AxiosError: Request failed with status code 400
at .<unknown>(Login POST)
at .?anon_0_(address at index.android.bundle:1:1024957)
at .throw((native):0:0)
at .asyncGeneratorStep(address at index.android.bundle:1:512579)
at ._throw(address at index.android.bundle:1:512897)
at .tryCallOne(InternalBytecode.js:53:16)
at .anonymous(InternalBytecode.js:139:27)
at .apply((native):0:0)
at .anonymous(address at index.android.bundle:1:192326)
at ._callTimer(address at index.android.bundle:1:191323)
at ._callReactNativeMicrotasksPass(address at index.android.bundle:1:191487)
at .callReactNativeMicrotasks(address at index.android.bundle:1:193401)
at .__callReactNativeMicrotasks(address at index.android.bundle:1:59173)
at .anonymous(address at index.android.bundle:1:58315)
at .__guard(address at index.android.bundle:1:59050)
at .flushedQueue(address at index.android.bundle:1:58226)
at .callFunctionReturnFlushedQueue(address at index.android.bundle:1:58082)
Stacktrace in v1.6.8
Non-fatal Exception: io.invertase.firebase.crashlytics.a: Request failed with status code 400
at .<unknown>(Login POST)
at .settle(address at index.android.bundle:1:1052843)
at .onloadend(address at index.android.bundle:1:1051698)
at .call((native):0:0)
at .dispatchEvent(address at index.android.bundle:1:218566)
at .setReadyState(address at index.android.bundle:1:201120)
at .__didCompleteResponse(address at index.android.bundle:1:198857)
at .apply((native):0:0)
at .anonymous(address at index.android.bundle:1:200689)
at .apply((native):0:0)
at .emit(address at index.android.bundle:1:53578)
at .apply((native):0:0)
at .__callFunction(address at index.android.bundle:1:59662)
at .anonymous(address at index.android.bundle:1:58173)
at .__guard(address at index.android.bundle:1:59110)
at .callFunctionReturnFlushedQueue(address at index.android.bundle:1:58131)
at .?anon_0_(address at index.android.bundle:1:1032334)
at .throw((native):0:0)
at .asyncGeneratorStep(address at index.android.bundle:1:512639)
at ._throw(address at index.android.bundle:1:512957)
at .tryCallOne(InternalBytecode.js:53:16)
at .anonymous(InternalBytecode.js:139:27)
at .apply((native):0:0)
at .anonymous(address at index.android.bundle:1:192386)
at ._callTimer(address at index.android.bundle:1:191383)
at ._callReactNativeMicrotasksPass(address at index.android.bundle:1:191547)
at .callReactNativeMicrotasks(address at index.android.bundle:1:193461)
at .__callReactNativeMicrotasks(address at index.android.bundle:1:59233)
at .anonymous(address at index.android.bundle:1:58375)
at .__guard(address at index.android.bundle:1:59110)
at .flushedQueue(address at index.android.bundle:1:58286)
at .callFunctionReturnFlushedQueue(address at index.android.bundle:1:58142)