4
根据http://docs.angularjs.org/api/ng.$http拦截器有以下方法:用例为requestError 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
触发,哪些使用案例,你能想到的?
在尝试发送请求失败后,如何显示连接错误消息? –
@AndreyShustariov hm当$ http无法连接资源,因为资源处于脱机状态时,会触发responseError –
好的。然后格式不正确的请求。例如,忘了设置url属性。 –