Last active
January 1, 2016 07:19
-
-
Save abruzzi/8110770 to your computer and use it in GitHub Desktop.
How to define a interceptor in AngularJS
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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