angular-ui / ui-router

The de-facto solution to flexible routing with nested views in AngularJS
http://ui-router.github.io/
MIT License
13.56k stars 3.01k forks source link

transition.abort() transition rejection does not invoke onError hook #3799

Closed delta711 closed 3 years ago

delta711 commented 4 years ago

This is a (check one box):

My version of UI-Router is: 1.0.25

Bug Report

Current Behavior:

Forcing a transition to fail via transition.abort() does not invoke onError.

The following transition:

$stateProvider.state({ 
  name: 'home.foo', 
  url: '/foo', 
  component: 'foo',
  resolve: { 
    fooData: function($transition$) { 
      //'foo data';    
      console.log('ABORTING TRANSITION!');    
      $transition$.abort(); 
      }
  },
});

With the following onError hook:

$transitions.onError({}, function () {
  console.log('onError CALLED!')
});

Appears in the console as follows:

ABORTING TRANSITION!
Transition #1-0: <- Rejected "Transition#1( 'home'{} -> 'home.foo'{} )", reason: Transition Rejection($id: 0 type: 3, message: The transition has been aborted, detail: undefined)

Expected Behavior:

If a Transition fails, its promise is rejected and the onError hooks are invoked. https://ui-router.github.io/ng2/docs/5.0.0/classes/transition.transition-1.html#onerror

Link to Plunker or stackblitz that reproduces the issue:

http://plnkr.co/edit/S4lac3e0I3PvKzzx

delta711 commented 4 years ago

I've worked around the issue by calling $q.reject() in the resolver (instead of transition.abort()). This allows me to handle special cases in an onError() handler.

stale[bot] commented 3 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.

This does not mean that the issue is invalid. Valid issues may be reopened.

Thank you for your contributions.