Hi,
I've posted several times in the stackoveflow about this question but no
one seems to understand my question or maybe they don't have the time to
read my entire post because they kept on giving me "wrong" answers.
Im using $http post and get in my project. Now, I'm having an issue with
redirection. I get a 302 status code when the session expires and when I
checked the response header I see that Location contains the url for my
login page which is correct. Now the problem is that the page isn;t
redirected to login. Is it because I used $http? It stays in the home page.
If its true that the browser should handle redirection status codes, then
why is it not redirecting to where it is supposed to be redirected?
Anyway, this is when I started resaerching on how to get the redirection
status code and i will create a code that will redirect the page to login
if the code sees that it receives a redirect code.
Some of the response from stackoverflow was to add this to my code. But
some argued that we cannot get 302 or any other redirect code.
app.factory('myHttpResponseInterceptor', ['$q', '$location', function($q,
$location) {
return function(promise) {
var success = function(response) {
if (response.status === 302) {
alert("success " + response.status);
$location.path('/login.html');
return response;
} else {
alert("success " + response.status);
return response;
}
};
var error = function(response) {
if (response.status == 401) {
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);
}
}
return $q.reject(response);
};
return promise.then(success, error);
};}]);
//Http Intercpetor to check auth failures for xhr requests
app.config(['$httpProvider', function($httpProvider) {
$httpProvider.interceptors.push('myHttpResponseInterceptor');}]);
Is it possible to handle 302 status code when using $http.get and
$http.post? how?
--
You received this message because you are subscribed to the Google Groups
"AngularJS" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/angular.
For more options, visit https://groups.google.com/d/optout.