Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Intercepting 401 or responses not working? #47

Open
nexeh opened this issue Apr 7, 2020 · 1 comment
Open

Intercepting 401 or responses not working? #47

nexeh opened this issue Apr 7, 2020 · 1 comment

Comments

@nexeh
Copy link

nexeh commented Apr 7, 2020

I didnt want to comment on issue #16 but i see the same issue. i really just care about intercepting a 401 but the response console.log is never hit. even if its the only thing in there. responseError does tho.


fetchIntercept.register({
  responseError: function(error) {
    console.log('responseError', error)
  }
});

fetchIntercept.register({
  response: function(response) {
    console.log('fetchIntercept response', response)
    if (response.status >= 401) throw new Error('Request error');
    return response;
  }
});

// Call fetch to see your interceptors in action.
fetch('http://google.com');
@ruifcnunes
Copy link

Hi!
I had the same problem. I've used the response interceptor with an async function that will check the response.ok and if its false, I call the function I created for the responseError with the response parameter as the error itself.
In essence, it's a bypass to the method that is already called for all other response status besides the 401.
hope it helps!

Cheers

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants