# 401 Never Being Caught by Interceptor

**URL:** <https://forum.ionicframework.com/t/401-never-being-caught-by-interceptor/9231>\
**Category:** ionic-v1\
**Created:** [September 5, 2014, 8:17pm UTC](https://forum.ionicframework.com/t/401-never-being-caught-by-interceptor/9231 "2014-09-05T20:17:12Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![mbeizer](https://avatars.discourse-cdn.com/v4/letter/m/bcef8e/32.png) [@mbeizer](https://forum.ionicframework.com/u/mbeizer)\
**Post date:** [September 5, 2014, 8:17pm UTC](https://forum.ionicframework.com/t/401-never-being-caught-by-interceptor/9231/1 "2014-09-05T20:17:12Z")

</div>

My suspicion is that this is more an Angular question than an Ionic question, but I’m not sure. I am trying to handle 401 status code from my server via an interceptor-- similar to [this forum question][1] or [this post’s][2] step number 8. In every other network request response, I hit the `response` property of the interceptor, but not with 401. My promises never reject and the loading screen never hides.

Any advice for the 401 black hole I am stuck in?

My interceptor:

```
.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'] = AuthorizationHeader.buildHashed(config, Session.key());
      }
      return config || $q.when(config);
    },

    response: function(response) {
      console.log('response');
      console.log(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;
})

```

I never see ‘401’ or ‘response error’. I can see from my network traffic I am getting a 401 from the server. 403s hit the `errorResponse` property, so I know that works.

Thanks in advance.  
[1]: [$ionicLoading in http interceptor](http://forum.ionicframework.com/t/ionicloading-in-http-interceptor/4599)  
[2]: [http://bitoftech.net/2014/06/09/angularjs-token-authentication-using-asp-net-web-api-2-owin-asp-net-identity/](http://bitoftech.net/2014/06/09/angularjs-token-authentication-using-asp-net-web-api-2-owin-asp-net-identity/)

---

<div class="post-metadata">

**Author:** ![mbeizer](https://avatars.discourse-cdn.com/v4/letter/m/bcef8e/32.png) [@mbeizer](https://forum.ionicframework.com/u/mbeizer)\
**Post date:** [September 8, 2014, 3:48pm UTC](https://forum.ionicframework.com/t/401-never-being-caught-by-interceptor/9231/2 "2014-09-08T15:48:07Z")

</div>

Is there any more information I can provide to inspire an answer from the community?

---

<div class="post-metadata">

**Author:** ![mbeizer](https://avatars.discourse-cdn.com/v4/letter/m/bcef8e/32.png) [@mbeizer](https://forum.ionicframework.com/u/mbeizer)\
**Post date:** [September 9, 2014, 6:43pm UTC](https://forum.ionicframework.com/t/401-never-being-caught-by-interceptor/9231/3 "2014-09-09T18:43:24Z")

</div>

For anyone out there struggling with the same issue: I think it is almost certainly an issue with the `www-authenticate` header I’m getting back from my server. [Here is a blog post](http://me.eekay.nl/index.php/2014/cordovaphonegap-and-the-missing-callback-for-401-unauthorized/) that leads me to think so.

I would LOVE any suggestions on a good work around since we can’t make `$http` behave synchronously.

---

<div class="post-metadata">

**Author:** ![Ryan\_IRL](https://avatars.discourse-cdn.com/v4/letter/r/9f8e36/32.png) [@Ryan\_IRL](https://forum.ionicframework.com/u/Ryan_IRL)\
**Post date:** [September 14, 2014, 8:53pm UTC](https://forum.ionicframework.com/t/401-never-being-caught-by-interceptor/9231/4 "2014-09-14T20:53:48Z")

</div>

Having the same issue here. I’ve tried to use an interceptor, but it’s almost like the app just sits waiting on an auth challenge, which means it gives me no advantage over promises.

Also, it seems to be related to a known bug: [https://issues.apache.org/jira/browse/CB-2415](https://issues.apache.org/jira/browse/CB-2415)

---

<div class="post-metadata">

**Author:** ![mbeizer](https://avatars.discourse-cdn.com/v4/letter/m/bcef8e/32.png) [@mbeizer](https://forum.ionicframework.com/u/mbeizer)\
**Post date:** [September 16, 2014, 2:56pm UTC](https://forum.ionicframework.com/t/401-never-being-caught-by-interceptor/9231/5 "2014-09-16T14:56:56Z")

</div>

@Ryan_IRL That has been my exact experience and the bug you mentioned is linked in the blog posted I linked. What have you been doing to work around this. Right now the best solution I have come up with is to use `$timeout` but that is quite distasteful.

---

<div class="post-metadata">

**Author:** ![Ryan\_IRL](https://avatars.discourse-cdn.com/v4/letter/r/9f8e36/32.png) [@Ryan\_IRL](https://forum.ionicframework.com/u/Ryan_IRL)\
**Post date:** [September 21, 2014, 12:49am UTC](https://forum.ionicframework.com/t/401-never-being-caught-by-interceptor/9231/6 "2014-09-21T00:49:24Z")

</div>

I have not found a solution yet. I may have to resort to a timeout as well until the bug is resolved.

---

<div class="post-metadata">

**Author:** ![mbeizer](https://avatars.discourse-cdn.com/v4/letter/m/bcef8e/32.png) [@mbeizer](https://forum.ionicframework.com/u/mbeizer)\
**Post date:** [September 25, 2014, 7:06pm UTC](https://forum.ionicframework.com/t/401-never-being-caught-by-interceptor/9231/7 "2014-09-25T19:06:42Z")

</div>

@Ryan_IRL this Stack Overflow-er suggested this: [http://stackoverflow.com/a/25941925/1254263](http://stackoverflow.com/a/25941925/1254263)

If you have control over your server, you can attempt to strip the `www-authenticate` from that side. I, unfortunately, do not have that option… 👎

HTH
