我正在开发一个角度Web应用程序,它需要与带有Bearer令牌的服务器通信 . 所以令牌将在每10分钟到期,并且在令牌到期后,下一个请求将导致statusCode 401和statusText未经授权的错误 .
我可以看到在令牌过期后我的chrome控制台中显示了此错误 . 当发生此错误时,会调用我的角度http拦截器的responseError处理程序,但rejectReason的状态为:0和statusText:'' .
我不知道为什么status和statusText没有填充,我需要检查代码401并再次调用服务器刷新我的令牌 .
请参阅我的拦截器代码和资源服务代码 .
任何帮助将非常感激 .
var addToken = function(user, $q, $injector){
var request = function(config){
if(user.profile.loggedIn){
config.headers.Authorization = 'Bearer ' + user.profile.token;
}
return $q.when(config);
};
var responseError = function(rejectReason){
//over here i want to check the error status
return $q.reject(rejectReason);
};
return{
request: request,
responseError: responseError
};
};