I am trying to implement a interceptor on Angular JS side , for which I will check for a particular response and navigate user to some other page . This is my interceptor
App.factory('InterceptorService',['$q', '$location', function( $q, $location, $http){
var InterceptorServiceFactory = {};
var _request = function(config){
console.log('Coming inside');
console.log(config);
return config;
}
var _response = function(response){
console.log('Coming inside for Result');
console.log(response);
if (response.data.code == "USER_TIMEDOUT") {
window.location.href = '/unrestricted/jsp/FormLogin.jsp';
alert(worked);
}
return response;
}
InterceptorServiceFactory.request = _request;
InterceptorServiceFactory.response = _response;
return InterceptorServiceFactory;
}]);
App.config(["$httpProvider", function ($httpProvider) {
$httpProvider.interceptors.push('InterceptorService');
}]);
This is my API response from Spring Interceptor
{
"code": "USER_TIMEDOUT",
"message": "User session timedout for requestUri=/services/search/Employee"
}
I am trying to check my response and check for the code and if the code matches I'm trying to take oput him to another screen . But whenever I see the response on console inside data it is having the Html .
Whene I analyse the Network tab , I am able to see API call has failed with response 401 . And all other HTML has loaded , while loading of the html . Response data is coming inside the Html . so what I am missing in my Interceptor ?