Skip to content

Instantly share code, notes, and snippets.

@sidonaldson
Created April 5, 2016 10:28
Show Gist options
  • Select an option

  • Save sidonaldson/689e79515168d10451f9fa10604cc79b to your computer and use it in GitHub Desktop.

Select an option

Save sidonaldson/689e79515168d10451f9fa10604cc79b to your computer and use it in GitHub Desktop.
How to add an Interceptor to log all AJAX requests in AngularJS
angular.module('test-app')
.factory('myHttpInterceptor', ['$q', function($q) {
return {
'response': function(res) {
console.log('New request', res, res.headers());
return res || $q.when(res);
},
'responseError': function(rej) {
if (canRecover(rej)) return responseOrNewPromise;
return $q.reject(re);
}
}
}])
.config(['$httpProvider', function($httpProvider) {
$httpProvider.interceptors.push('myHttpInterceptor');
}]);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment