error.response undefined in simple interceptor
See original GitHub issueAxios v0.17.1
instance.interceptors.response.use(res => res, error => {
console.log('ERROR');
console.log(error);
console.log('response:');
console.log(error.response);
});
result
ERROR
index.js:47 Error: Network Error
at createError (createError.js:16)
at XMLHttpRequest.handleError (xhr.js:87)
index.js:48 response:
index.js:49 undefined
confused at to why this is happening, i’m trying to retry requests based on error.response.status but error.response isn’t always defined. Is this expected behaviour? If so what is your recommended fix?
Issue Analytics
- State:
- Created 6 years ago
- Reactions:11
- Comments:6
Top Results From Across the Web
axios interceptors response undefined - Stack Overflow
It appears my error.response is undefined. I'm not sure what is wrong? any ideas? console.dir of the error.
Read more >Setting Up Axios Interceptors For HTTP Calls With Refresh ...
In this tutorial, I'll show how to use Axios interceptors to intercept HTTP requests and how to use Refresh Tokens with Axios.
Read more >[Solved]-axios interceptors response undefined-Vue.js
Shameless self-promotion, I've published a simple Axios plugin called ... axios.interceptors.response.use( response => response, error => { if (typeof ...
Read more >How to Implement a Request Interceptor Like Axios
config.data = undefined; } return config; })//intercept response to check the data axios.interceptors.response.use(function(config) {
Read more >axios interceptors and errors : r/reactnative - Reddit
If you want to catch the error outside of .use() you'll have to throw it. api.interceptors.response.use(. (response: AxiosReaponse) => response,.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I’m running this issue too. I want to control user logged in state into interceptors. For instance, if my interceptors catch a response with status 401, I want to logoff / redirect this user.
@SeeThruHead I had this issue when the response did not include the
Access-Control-Allow-Origin
header. The error response was received, but disallowed by CORS. When that happens, it looks like axios doesn’t actually seterror.response
, even though there was a received response.So, at least in my case, the fix was to make sure
Access-Control-Allow-Origin: *
was included in the response’s headers when there was an error.