Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Could not use catch or finally for Auth.currentUser() when having 401 error and use AuthProvidor #86

@leomao10

Description

@leomao10

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions