3

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!

6
  • 1
    Perhaps check $state.current and if it's already signin then don't do $state.go('signin') again? It should work Commented Sep 29, 2017 at 9:19
  • Ok ill check, Thanks! Commented Sep 29, 2017 at 9:21
  • Still dont work. Commented Sep 29, 2017 at 9:24
  • $state.name returns "" Commented Sep 29, 2017 at 9:24
  • 1
    Multiple transitions to the same state (signin) are ignored in recent versions of ui-router. See ui-router.github.io/guide/transitions#atomicity Commented Oct 1, 2017 at 16:29

1 Answer 1

6

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);
});

Details

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.