2014-02-20 172 views

回答

1

我不知道你是如何工作,但我写的那些看起来完全不同..

var interceptor = ['$rootScope', '$q', "Base64", function (scope, $q, Base64) { 
    function success(response) { 
     return response; 
    } 
    function error(response) { 
     var status = response.status; 
     if (status == 401) { 
      window.location = "/account/login?redirectUrl=" + Base64.encode(document.URL); 
      return; 
     } 
     // otherwise 
     return $q.reject(response); 
    } 
    return function (promise) { 
     return promise.then(success, error); 
    } 
}]; 
$httpProvider.responseInterceptors.push(interceptor); 

你可以检查出full code here

+0

对于迟到的回复感到抱歉。其实我忘了设置transformError。所以你的回答是对的 –