Created
September 10, 2015 14:24
-
-
Save annapoulakos/a7ce35575d807401b918 to your computer and use it in GitHub Desktop.
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
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