I\'m using angularjs http service in my app, and I noticed this in the website:
If the AJAX call succeeds (the server sends back an HTTP code between
Please note that this is specific to my project.
Goal: Catch 302 status code and redirect the page (to login in my case).
Result: In firebug, I could see that the response code is 302 but then I found out that angularjs returns 200 by simply printing the value of status (response.status). So at first you'd thought that you're hopeless. But in my case, what I did was get the data (response.data), look for the string that could be only found in my login page. Then that's it. problem solved :D
The idea was taken here.
Here's the code
app.factory('redirectInterceptor', function($q,$location,$window){
return {
'response':function(response){
if (typeof response.data === 'string' && response.data.indexOf("My Login Page")>-1) {
console.log("LOGIN!!");
console.log(response.data);
$window.location.href = "/login.html";
return $q.reject(response);
}else{
return response;
}
}
}
});
app.config(['$httpProvider',function($httpProvider) {
$httpProvider.interceptors.push('redirectInterceptor');
}]);