I have been looking for a way of managing the http errors that I can have in my angular application. I have been capturing them separately, but I would like to manage them globally. I am using $resource and $http for my http calls. Are there any way of managing them globally?
Try $http interceptor:
Quoted from the docs:
angular.module('app',[]).config(function($httpProvider){
$httpProvider.interceptors.push(function($q, dependency1, dependency2) {
return {
'request': function(config) {
return config;
},
'response': function(response) {
// do something on success
return response || $q.when(response);
},
'responseError': function(rejection) {
// do something on error
return $q.reject(rejection);
}
};
});
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With