Angular http interceptor responseError doesn't have statusText

204 views Asked by At

I am working on an angular web app which need to communicate with a server with Bearer token. so the token will expire in every 10 mins, and after the token expires, the next request will result an error with statusCode 401 and statusText unauthorized.

I can see this error is shown in my chrome console after the token expires. And my angular http interceptor's responseError handler is invoked when this error occurs, but the rejectReason has status: 0 and statusText: ''.

I don't know why the status and statusText are not populated, I need to check the code 401 and call the server again to refresh my token.

Please see my interceptor code and resources service code.

any help would be much appreciated.

  var addToken = function(user, $q, $injector){

    var request = function(config){
      if(user.profile.loggedIn){
        config.headers.Authorization = 'Bearer ' + user.profile.token;
      }
      return $q.when(config);
    };

    var responseError = function(rejectReason){
       //over here i want to check the error status
       return $q.reject(rejectReason);
    };

    return{
      request: request,
      responseError: responseError
    };

  };
0

There are 0 answers