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屬性。 –