2
What I need:
I need when http request returns error 401 or 403 the user is redirected to login screen.
Problem:
The problem happens when I inject $state into my Factory, causes circular dependency error:
Uncaught Error: [$injector:cdep] Circular dependency found: $http <- $templateFactory <- $view <- $state <- Interceptorrequestfactory <- $http <- $translatePartialLoader http://errors.angularjs.org/1.5.9/$injector/cdep? P0=%24http%20%3C-%20%24tem... erceptorRequestFactory%20%3C-%20%24http%20%3C-%20%24translatePartialLoader
Code:
(function () {
'use strict';
angular
.module('app.factory')
.factory('InterceptorRequestFactory', InterceptorRequestFactory);
function InterceptorRequestFactory($q, $state) {
return{
request: function(config){
return config;
},
requestError: function(rejection){
console.log(rejection);
return $q.reject(rejection);
},
response: function(response){
return response
},
responseError: function(rejection){
console.log(rejection);
if(rejection.status === 401 || rejection.status === 403){
$state.go('app.login');
}
else{
return $q.reject(rejection);
}
}
};
}
})();