角度拦截器不拦截错误

时间:2016-09-19 16:05:26

标签: javascript angularjs

我有拦截器,但是所有响应只进入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发出请求吗?

0 个答案:

没有答案
相关问题