Skip to content

Instantly share code, notes, and snippets.

@annapoulakos
Created September 10, 2015 14:24
Show Gist options
  • Save annapoulakos/a7ce35575d807401b918 to your computer and use it in GitHub Desktop.
Save annapoulakos/a7ce35575d807401b918 to your computer and use it in GitHub Desktop.
const ModuleName = 'ModuleParent.InterceptorModule';
const ModuleDeps = [];
var InterceptorModule = angular.module(ModuleName, ModuleDeps);
InterceptorModule.factory('myInterceptor', ['$q', function ($q) {
var interceptor = {
request: function (config) {
console.log('myInterceptor.request', config);
return config;
},
requestError: function (config) {
console.log('myInterceptor.requestError', config);
return config;
},
response: function (response) {
console.log('myInterceptor.response', response);
var deferred = $q.defer();
deferred.resolve(response);
return deferred.promise;
},
responseError: function (response) {
console.log('myInterceptor.responseError', response);
var deferred = $q.defer();
deferred.reject(response);
return deferred.promise;
}
};
return interceptor;
}]);
InterceptorModule.config(['$httpProvider', function ($httpProvider) {
$httpProvider.interceptors.push('myInterceptor');
}]);
export default InterceptorModule;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment