question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

error.response undefined in simple interceptor

See original GitHub issue

Axios 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:closed
  • Created 6 years ago
  • Reactions:11
  • Comments:6

github_iconTop GitHub Comments

2reactions
AllanPinheiroDeLimacommented, Aug 31, 2018

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.

1reaction
olafal0commented, Jun 13, 2018

@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 set error.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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found