Created
April 5, 2016 10:28
-
-
Save sidonaldson/689e79515168d10451f9fa10604cc79b to your computer and use it in GitHub Desktop.
How to add an Interceptor to log all AJAX requests in AngularJS
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
| 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