Catching Axios Result is Undefined
See original GitHub issueDescribe the issue
Having an issue which I don’t know if I’m trying to use axios wrong or not but it looks like I’ve got the same syntax as shown in documentation. When using axios.get()
I’ll get the result I’m looking for.
I’m calling IActionResult
controller endpoints using axios
and I’m intentionally returning BadRequest("Test Message");
to see if I can send back any message I want. With the code below I catch the error but the variable err
is undefined when using axios.post()
. I do the same thing below with axios.get()
and I’m catching the error which does get populated correctly. Does this same thing not happen with axios.post()
?
If I look in dev tools and view the errored network call I can see my returned message in the response so it is getting sent back. But It doesn’t seem to be getting picked up when catching it.
Example Code
axios
.post('/Form/SavePersonData', _this.donation)
.then(function(res) {
})
.catch(function(err) {
alert(err);
console.log(err);
});
Environment:
- Axios Version [e.g. 0.18.0]
- OS: [e.g. iOS 12.1.0, OSX 10.13.4]
- Browser [e.g. Chrome, Safari]
- Browser Version [e.g. 22]
- Additional Library Versions [e.g. React 16.7, React Native 0.58.0]
Additional context/Screenshots Add any other context about the problem here. If applicable, add screenshots to help explain.
Issue Analytics
- State:
- Created 5 years ago
- Comments:5
Top GitHub Comments
Reject the axios promise in axios interceptors using Promise.reject(error.response).
@DanJ210 I am not familiar with IActionResult controller endpoints. But did you support POST method in the server side? Anyway, we suggest users ask similar questions in stackoverflow, instead of Github issues. Thanks.