Interceptor automatically captures all 401s and prevents other interceptors from having an opportunity to examine them
jeremy-nation opened this issue · 0 comments
Hello!
First, I'd like to say thanks for creating this project! It's saved me a lot of time and is (almost) perfect for my needs.
In my particular scenario, I'd like to use this interceptor to handle some 401s but not all of them. The ignoreAuthModule
config flag works great for scenarios where you know ahead of time that a particular call will produce a 401 that should be ignored.
For our application, a 401 can be returned for different scenarios and we may not know how the 401 should be handled until the response is received. It would be great if the interceptor had the ability to examine the response based on some custom criteria to determine whether or not it should let it pass through or capture it. The code below illustrates this idea (From line 56 in http-auth-interceptor.js)
Original
if (!config.ignoreAuthModule) {
...
}
// otherwise, default behaviour
return $q.reject(rejection);
Proposal
if (!config.ignoreAuthModule && passesCustomCriteria(rejection)) {
...
}
// otherwise, default behaviour
return $q.reject(rejection);
Using the above logic, the 401 is allowed to propagate to other interceptors and is not captured if it doesn't match the custom criteria.