Reputation: 2237
I have a HTTPInterceptor that should go to signin state whenever a 401 is caught. My problem is that I have 3 asynchronous call to API that almost starts the same time. When all of them returns 401, i got an error with the following message:
Transition Rejection($id: 0 type: 6, message: The transition errored, detail: "undefined")
This is my code for my interceptor:
switch (response.status) {
case 401:
let url = $location.absUrl();
// This condition supposed to prevent
// going to signin state again after a response of 401.
// Not really sure if ui-router will navigate still on the same
// state. So maybe this condition is not needed?
if (url.indexOf('sign-in') !== -1) {
deferred.reject(response.data.error);
} else {
if ($transitions._transitionCount === 1) {
$state.go('signin');
}
}
break;
What ive tried so far is to check the transitionCount but still the error persist.
Thanks!
Upvotes: 3
Views: 15812
Reputation:
In UI-Router legacy, users often complained that resolves would “swallow errors”. The errors were output as a $stateChangeError event, but applications sometimes didn’t listen to the event.
In UI-Router 1.0, we’ve added a default error handler. When a call to $state.go() fails, we pass the error to StateService.defaultErrorHandler.
You can handle this type of error with
$state.defaultErrorHandler(function(error) {
// This is a naive example of how to silence the default error handler.
console.log(error);
});
Upvotes: 6