【发布时间】:2017-03-03 19:31:56
【问题描述】:
我正在尝试在 Angular JS 端实现一个拦截器,为此我将检查特定响应并将用户导航到其他页面。这是我的拦截器
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');
}]);
这是我来自 Spring Interceptor 的 API 响应
{
"code": "USER_TIMEDOUT",
"message": "User session timedout for requestUri=/services/search/Employee"
}
我正在尝试检查我的回复并检查代码,如果代码匹配,我正在尝试将他带到另一个屏幕。但是,每当我在控制台内部数据上看到响应时,它就会有 Html 。
当我分析“网络”选项卡时,我可以看到 API 调用失败,响应为 401。并且所有其他的 HTML 已经加载完毕,同时加载了 html。响应数据来自 Html 。那么我的拦截器中缺少什么?
【问题讨论】:
标签: javascript html angularjs intercept