I have an Angular component based application where individual components load their respective data. When errors occur, I usually want the component to display an error message.
However, in some cases, I would like the component to ignore the error and leave it to some global error handling mechanism to catch it.
interceptor:
angular.module("...").factory("httpInterceptor", function($q) {
return {
responseError: function(response) {
return $q.reject("I AM CALLED FIRST")
}
})
Serivce:
angular.module("...").service("myService", function($http){
return {
fetchData: function(){
return $http.get("...")
}
}
})
Controller:
angular.module("...").controller("MyController", function(myService){
myService.fetchData()
.then(function(){ ... })
.catch(function() {
})
})
In most cases, I want the error to be processed in the controller (at point (2)). If the controller decides to ignore the error (omit capture), the error can still be detected in the interceptor.
, , , . , ( , , ).
HTTP, ?