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
[2]: http://bitoftech.net/2014/06/09/angularjs-token-authentication-using-asp-net-web-api-2-owin-asp-net-identity/