加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

angularjs – requestError http拦截器的用例

发布时间:2020-12-17 17:13:03 所属栏目:安全 来源:网络整理
导读:根据 http://docs.angularjs.org/api/ng.$http,拦截器有以下方法: request: function(config) { //we could manipulate query here return config || $q.when(config);},requestError: function(rejection) { // what is the use case of this? return $q.r
根据 http://docs.angularjs.org/api/ng.$http,拦截器有以下方法:

request: function(config) {
  //we could manipulate query here
  return config || $q.when(config);
},requestError: function(rejection) {
  // what is the use case of this?
  return $q.reject(rejection);
},response: function(response) {
  // response.status === 200
  return response || $q.when(response);
},responseError: function(rejection) {
  // when response failed ...
  return $q.reject(rejection);
}

requestError是如何触发的,你能想到什么用例?

解决方法

一个有趣的用例是拆除/撤消在请求之前设置的内容,并且在响应之后会被拆除.例子:

>装载指标
>叠加
>禁用表单字段

现在,当请求无法发送或被另一个拦截器拒绝时,requestError使您有机会正确操作并删除该加载指示符或启用表单字段.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读