title: AngularJS Interceptor Never Catches 401 Error
body: <p>I'm using Angular v1.2.20 with the <a href="http://ionicframework.com" rel="nofollow">Ionic Framework</a>. I have seen many articles and posts about how to handle 401 errors from the server by using an interceptor and pushing it into the <code>$httpProvider.interceptors</code> array.</p>
  
  <p>For some reason, 401 responses never get caught by the <code>repsonseError</code> function in my interceptor. The promise I am expecting to reject never rejects and my app just seems to hang (<code>loading:hide</code> from below never gets called). I can see from my web debugging proxy that a 401 is definitely returned from the server.</p>
  
  <p>My interceptor:</p>
  
  <pre><code>.factory('interceptorService', function($rootScope, $q, Session, AuthorizationHeader) {
    var interceptorService = {
      request: function(config) {
        $rootScope.$broadcast('loading:show');
        config.headers['Authentication-Key'] = Session.key();
        config.headers['Authentication-Timestamp'] = (new Date().toJSON());
        config.headers['Authentication-Account'] = Session.accountName();
        if(typeof config.headers['Authorization'] === 'undefined') {
          config.headers['Authorization'] = 'Custom-HMAC-SHA512 ' + AuthorizationHeader.buildHashed(config, Session.key());
        }
        return config || $q.when(config);
      },
  
      response: function(response) {
        if(response.status === 401) {
          console.log('401');
        }
        $rootScope.$broadcast('loading:hide');
        return response || $q.when(response);
      },
  
      requestError: function(config) {
        $rootScope.$broadcast('loading:hide');
        return $q.reject(config);
      },
  
      responseError: function(response) {
        console.log('response error');
        $rootScope.$broadcast('loading:hide');
        return $q.reject(response);
      }
    };
  
    return interceptorService;
  })
  </code></pre>
  
  <p>I can confirm that the interceptor is working as, when I get a 403 back from the server, I can see 'response error' in my console log. Please also note that this happens regardless of HTTP verb used. It's happening with HEAD calls and DELETE calls.</p>
  
  <p>Any help is very much appreciated.</p>
  
  <h2>## Edit</h2>
  
  <p>It appears that this problem is caused by cordova/phonegap not being able to handle the <code>www-authenticate</code> header in the 401 response as referenced <a href="http://me.eekay.nl/index.php/2014/cordovaphonegap-and-the-missing-callback-for-401-unauthorized/" rel="nofollow">in this blog post</a>.</p>
  
  <p>If anyone has any ideas on how best to handle that, I'm all ears.</p>