I have a factory and its function is to handle redirect status codes. If it sees that the status code is 302, it will redirect the page to the login page.
app.factory('redirectInterceptor', function($q,$location){
return {
responseError : function(response){
return promise.then(
function success(response) {
if(response.status === 302){
alert("success " +response.status);
$location.path('/login.html');
return response;
}
else{
alert("success " +response.status);
return response;
}
},
function error(response) {
if(response.status === 302){
alert("error " +response.status);
$location.path('/public/login.html');
return $q.reject(response);
}
else{
alert("error " +response.status);
return $q.reject(response);
}
}
);
}
}
});
app.config(['$httpProvider',function($httpProvider) {
$httpProvider.interceptors.push('redirectInterceptor');
}]);
But I get an error once the server returns 302. here it is
Error: promise is not defined
What have I done wrong?