Hi There,
Our project is currently using angular_devise, and there are some code like these in our project:
Auth.currentUser().then(
function(user){
$rootScope.$broadcast(AUTH_EVENTS.loginSuccess);
}, function(error){
$rootScope.$broadcast(AUTH_EVENTS.loginFailed)
}).finally(function(){
$rootScope.$broadcast(AUTH_EVENTS.loginCompleted)
})
However, we can't do that when server return 401 unauthorized error. Because the request will be handled by AuthInterceptor, and AuthInterceptor will return a promise that doesn't resolve/reject, and all following chained promises will be ignore.
Here is the code I am referring:
https://github.com/cloudspace/angular_devise/blob/master/src/401.js#L22
if (intercept && response.status === 401) {
var deferred = $q.defer();
$rootScope.$broadcast('devise:unauthorized', response, deferred);
return deferred.promise;
}
No sure if it is designed on purpose, but I think it would be made sense to reject the promise, so that we can have another option to handle the error instead of listen to 'devise:unauthorized' event