Tho*_*ock 6 angularjs restangular
官方的restangular文档提供此代码示例以在ErrorInterceptor中重试请求:
var refreshAccesstoken = function() {
var deferred = $q.defer();
// Refresh access-token logic
return deferred.promise;
};
Restangular.setErrorInterceptor(function(response, deferred, responseHandler) {
if(response.status === 403) {
refreshAccesstoken().then(function() {
// Repeat the request and then call the handlers the usual way.
$http(response.config).then(responseHandler, deferred.reject);
// Be aware that no request interceptors are called this way.
});
return false; // error handled
}
return true; // error not handled
});
Run Code Online (Sandbox Code Playgroud)
但是,正如它在评论中所说,第二次尝试不会触发任何拦截器,因为它直接使用$ http.
有没有办法让第二个请求也通过Restangular管道并执行ErrorInterceptor?
| 归档时间: |
|
| 查看次数: |
3344 次 |
| 最近记录: |