Skip to content

Instantly share code, notes, and snippets.

@iamtekeste
Created October 6, 2016 18:38
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 iamtekeste/c113fe2e92be60055704b753e71c7f13 to your computer and use it in GitHub Desktop.
Save iamtekeste/c113fe2e92be60055704b753e71c7f13 to your computer and use it in GitHub Desktop.
Angular HTTP interceptors
(function(){
angular.module('awesomeApp', [])
.config(function($httpProvider){
$httpProvider.interceptors.push('myInterceptors');
})
.factory('myInterceptors', function(){
return {
request: function(config){
//any code you put here will be executed right before you make the request
//config here refers to the $http config object, you are okay to modify it
return config;
},
requestError: function(rejection){
// this gets called if previous interceptor threw an error
},
response: function(response){
//this function receives the http response object, you are okay to modify it
return response
},
responseError: function(rejection){
// this gets called if previous interceptor threw an error
}
}
})
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment