Created
October 6, 2016 18:38
-
-
Save iamtekeste/c113fe2e92be60055704b753e71c7f13 to your computer and use it in GitHub Desktop.
Angular HTTP interceptors
This file contains 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
(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