用例for requestError http拦截器

时间:2014-01-09 18:10:54

标签: angularjs

根据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是如何触发的,您能想到哪些用例?

1 个答案:

答案 0 :(得分:3)

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

  • 加载指标
  • 覆盖
  • 已停用的表单字段

现在,当请求无法发送或被其他拦截器拒绝时,requestError会让您有机会采取相应行动并删除该加载指示符或启用表单字段。