I am very new to the angularjs, basically i want to check all $http request with angularjs interceptor and if the response data match 401 then redirect to login page
Any help appreciated
I am very new to the angularjs, basically i want to check all $http request with angularjs interceptor and if the response data match 401 then redirect to login page
Any help appreciated
You can find more details on interceptors here.
In short, you can put following code in config section of your main module.
$httpProvider.interceptors.push(function($q, dependency1, dependency2) {
return {
response: function(response){
return promise.then(
function success(response) {
return response;
},
function error(response) {
if(response.status === 401){
//your redirection code goes here
return $q.reject(response);
}
else{
return $q.reject(response);
}
});
}
}
});