$routeChangeError not called on $q.reject $routeChangeError not called on $q.reject angularjs angularjs

$routeChangeError not called on $q.reject


Okay so under the assumption you are using the Angular UI router, I believe you are just translating the error handler incorrectly from the official one.

From the docs for $state:

Fired when an error occurs during transition. It's important to note that if you have any errors in your resolve functions (javascript errors, non-existent services, etc) they will not throw traditionally. You must listen for this $stateChangeError event to catch ALL errors.

And the parameters for this handler are different, try something like this:

$rootScope.$on("$stateChangeError", function(event, toState, toParams, fromState, fromParams, error) {  if (error && !error.authenticated) {    $location.path("/login");  }});

Here's a description of the parameters with the important one bolded:

  • event – {Object} – Event object.
  • toState – {State} – The state being transitioned to.
  • toParams – {Object} – The params supplied to the toState.
  • fromState – {State} – The current state, pre-transition.
  • fromParams – {Object} – The params supplied to the fromState.
  • error – {Error} – The resolve error object.