我有拦截器,但是所有响应只进入request()
,即使返回了500个代码
这是我的代码
angular.module("BusinessTool").factory('InterceptorService',['$q', '$location', function( $q, $location, $http ){
resp = $.get('api/me.json');
return {
request: function(config){
// everything is ok
return config;
},
responseError: function(rejection) {
//error here. for example server respond with 401
if (resp.status == 401) {
window.location.href = '/';
}
return $q.reject(rejection);
}
}
}]);
angular.module("BusinessTool").config(['$httpProvider', function($httpProvider) {
$httpProvider.interceptors.push('InterceptorService');
}]);
我希望在401的情况下重定向到/
url。也可以强制拦截器在每次请求之前向api/me.json
发出请求吗?