Angularjs requestError http拦截器的用例

Angularjs requestError http拦截器的用例,angularjs,Angularjs,据介绍,拦截器有以下几种方法: 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

据介绍,拦截器有以下几种方法:

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
让您有机会采取适当的行动,删除加载指示器或启用表单字段。

在发送请求失败后显示连接错误消息如何?@AndreyShustariov hm no当$http由于资源脱机而无法连接到资源时,responseError是triggeredOk。然后是格式错误的请求。例如,忘记设置url属性。