I have the same problem.
I'm not sure, but it looks like $location.path(...) does not change location, because the application waits until all promises are resolved and the promise inside the interceptor is rejected ( return $q.reject(response); )
In my case, the service that makes the HTTP request is placed inside the resolve section of the state of the UI router, so I can use the $stateChangeError event to handle the error. (for ngRoute use the $ routeChangeError event)
Hope this can help you :)
NB My application backend returns custom error messages to 401 response body
PS There must be some better solution.
UPDATE:
More universal workaround:
interceptor inside module.config
... responseError: function (response) { if (response && response.status === 401) { $rootScope.$emit('loginRequired'); } return $q.reject(response); } ...
and an event handler somewhere in the module.run section
$rootScope.$on('loginRequired', function() { $location.path('/login'); });
(I tested the handler with $state.go('login') , but $location.path('/login'); should work too :))
source share