Skip to content

Instantly share code, notes, and snippets.

@abruzzi
Last active January 1, 2016 07:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save abruzzi/8110770 to your computer and use it in GitHub Desktop.
Save abruzzi/8110770 to your computer and use it in GitHub Desktop.
How to define a interceptor in AngularJS
app.factory('MyHTTPInterceptor', function($q) {
return {
// On response success
response: function (response) {
console.log(response);
// Return the response or promise.
return response || $q.when(response);
},
// On response failture
responseError: function (rejection) {
console.log(rejection);
// Return the promise rejection.
return $q.reject(rejection);
}
};
});
app.config(function($httpProvider) {
$httpProvider.interceptors.push('MyHTTPInterceptor');
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment