You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
According to https://axios-http.com/docs/handling_errors, it is possible that, an error is thrown and there is response key in error. axios.get('/user/12345') .catch(function (error) { if (error.response) { // The request was made and the server responded with a status code // that falls out of the range of 2xx console.log(error.response.data); console.log(error.response.status); console.log(error.response.headers); } else if (error.request) { // The request was made but no response was received // error.request is an instance of XMLHttpRequest in the browser and an instance of // http.ClientRequest in node.js console.log(error.request); } else { // Something happened in setting up the request that triggered an Error console.log('Error', error.message); } console.log(error.config); });
And following is my experient.
1 I have an url that will return 404, and there is content in the response body.
2 If I call the url by resp = axios.get(url), an error is thrown and there is no response key in error, but there is request key in error.
3 I set validateStatus to always to return true. Now no error was thrown. The get function normally return and resp is assigned.
So anytime axios throw an error, there is no response in error. The document is incorrect.
Now the question is, when axis throw an error and has response key in error?
I want to axios to thrown error when the http status code is 404 and I want to read the response body from error.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
According to https://axios-http.com/docs/handling_errors, it is possible that, an error is thrown and there is response key in error.
axios.get('/user/12345') .catch(function (error) { if (error.response) { // The request was made and the server responded with a status code // that falls out of the range of 2xx console.log(error.response.data); console.log(error.response.status); console.log(error.response.headers); } else if (error.request) { // The request was made but no response was received //
error.requestis an instance of XMLHttpRequest in the browser and an instance of // http.ClientRequest in node.js console.log(error.request); } else { // Something happened in setting up the request that triggered an Error console.log('Error', error.message); } console.log(error.config); });
And following is my experient.
1 I have an url that will return 404, and there is content in the response body.
2 If I call the url by resp = axios.get(url), an error is thrown and there is no response key in error, but there is request key in error.
3 I set validateStatus to always to return true. Now no error was thrown. The get function normally return and resp is assigned.
So anytime axios throw an error, there is no response in error. The document is incorrect.
Now the question is, when axis throw an error and has response key in error?
I want to axios to thrown error when the http status code is 404 and I want to read the response body from error.
Beta Was this translation helpful? Give feedback.
All reactions