You will need to decide or reject the promise. I would suggest that the URL switch will occur in the $stateChangeError event $stateChangeError , which will be fired by dropping the promise. You can pass the location you want to go to reject([data]) to the listener.
http://fiddle.jshell.net/L9jxf/2/
Some promise that they will deviate after a timeout (simulates a server call)
protected: ['$timeout', '$q', function ($timeout, $q) { var deferred = $q.defer(); $timeout(function () { deferred.reject({type:'redirect',location:'401'}); }, 1000); return deferred.promise; }]
This refers to failure
app.run(function ($rootScope, $state) { $rootScope.$on('$stateChangeError', function (e, to, toParams, from, fromParams, error) { if (error.type === 'redirect') { $state.transitionTo(error.location); } }); });
source share