Reputation: 355
I have an interceptor that receives a 401 (unauthorized).
Everything looks good, however while i do a single request, the interceptor gets fired twice.Very strange.
App.factory('HttpResponseInterceptor', ['$q', '$injector', '$location','ModalService', function ($q, $injector, $location, ModalService) {
return {
responseError: function (response) {
if (response.status === 401) {
console.log("401");
}
return $q.reject(response);
}
}
}]);
App.config(['$httpProvider', function ($httpProvider) {
$httpProvider.interceptors.push('HttpResponseInterceptor');
}]);
I get in the chrome debugging console " 2 401", meaning it got fired twice
Here is the code that fires the network call.Its only fired once, i checked it via fiddle.
The controller:
angular.module('App')
.controller('HomeCtrl',['$scope','$http', function ($scope, $http) {
$scope.Open = function () {
$http.get('/Home/GetSum').
then(function (response) {
alert(response);
});
}
}])
and the view:
<button ng-controller="HomeCtrl" ng-click="Open()">OPEN</button>
Note that i am using Ui router.
Upvotes: 0
Views: 954
Reputation: 278
Try remove the $q.reject(response).
If the response return 401 it is automatically rejected
Upvotes: 2