interceptor in angularjs example
Example: angularjs interceptor
$provide.factory('myHttpInterceptor', function($q, dependency1, dependency2) {
return {
'request': function(config) {
return config;
},
'requestError': function(rejection) {
if (canRecover(rejection)) {
return responseOrNewPromise
}
return $q.reject(rejection);
},
'response': function(response) {
return response;
},
'responseError': function(rejection) {
if (canRecover(rejection)) {
return responseOrNewPromise
}
return $q.reject(rejection);
}
};
});
$httpProvider.interceptors.push('myHttpInterceptor');
$httpProvider.interceptors.push(function($q, dependency1, dependency2) {
return {
'request': function(config) {
},
'response': function(response) {
}
};
});