axios: Async await error message?
When using .catch()
I get a proper error message with response
, stack
and message
but when i’m using async/await
wrapped in a try/catch
I only get config
Example:
try {
const { data } = await axios.get(forumUrl)
resolve(data)
} catch (error) {
console.log(error) //{config:{...}}
reject(error)
}
Any idea why?
- axios version: e.g.: latest
About this issue
- Original URL
- State: closed
- Created 7 years ago
- Reactions: 51
- Comments: 17
try returning
error.response
, it worked for meHello, Are you using it in the browser or in node? If I do this
I get [“config”, “request”, “response”] “Network Error” so it seems to work properly It seems weird to have something different as async await are just wrapper around promises
Having the same problem here. I’m using node 10.7.0, react-native 0.55.4, axios 0.18.0 A failed request from await axios.request(config) triggers catch block, but error argument is undefined. Reverting to .catch(error => onError(error)) works as documented.
Greetings folks! Can y’all please share a full code sample that includes the enclosing function? This totally “works on my machine”:
Also facing this issue:
Fails with:
What confuses me is that this isn’t caught by the try-catch. Node even says:
It’s like the try catch doesn’t exist…
I am having the same issue here. Two years? Seriously guys…
It seems possible to “cure” this by adding a
.catch()
to axios/lib/core/dispatchRequest.js:85. Perhaps this is the right approach, since the network events are asynchronous?Closed due to stale and no one proves with a replicable code sample. If someone persist it is an issue of axios, feel free to open a new issue. Thanks.
It’s been two years since this has been created, has it been fixed? I still have the same issue