- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
官方 retangular 文档 provides此代码示例在 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
});
最佳答案
实际上,使用 Restangular 发出的请求使用了被设计为只解决一次的 promise 。如果被拒绝,您将无法重新发送。
我真的不知道你是否想要一个可重复使用的 errorInterceptor
与否,但该服务的工作方式似乎不允许仅从 response object config
重新构建 Retangular 对象。 .
您可以做的一件事是保存对您的对象的引用,然后在拦截器中使用它。
你应该有你的理由,但我必须警告你这一点,因为万一失败,如果它持续存在,你最终可能会无限调用,因为 Retangular 将始终调用 errorInterceptor
.
我模拟了一点 Plunkr对于演示,只需打开您的网络选项卡并单击按钮,您应该会看到所有请求都通过那里。
关于angularjs - 在拦截器中重试 Retangular 调用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25725896/
官方 retangular 文档 provides此代码示例在 ErrorInterceptor 中重试请求: var refreshAccesstoken = function() { va
在 Retangular 中是否有任何内置方法可以为 ajax/$http 调用提供超时? 以及如何使用 Retangular 为 ajax/$http 调用编写一个包装器以通过超时重试。一个工厂??
我已经开始使用 Restangular,它似乎是一个非常好的库。但是我有以下查询。为了更新一个对象,我使用下面的代码 Restangular.one("accounts", $scope.accoun
我目前正在将我的应用程序从 $resouce 迁移到 Restangular,但我无法理解应该在何处实现 extendModel。 通读可用的幻灯片 here在幻灯片 46 上,它显示了以下两个片段。
我在我的一件作品中使用了 Restangular 服务器人员给了我以下调用,我需要将它们集成到 AngularJS 客户端 PUT api/partners/password – RequestPay
我正在使用 Restangular 构建一个应用程序。我会在一个地方处理响应拦截器中的 401、403、500 等错误。 这是我写的: RestangularProvider.setResponseE
我是一名优秀的程序员,十分优秀!