Skip to content

Instantly share code, notes, and snippets.

@wwwmarcos
Last active March 23, 2016 19:22
Show Gist options
  • Save wwwmarcos/cd29f2b9d8067992e2fb to your computer and use it in GitHub Desktop.
Save wwwmarcos/cd29f2b9d8067992e2fb to your computer and use it in GitHub Desktop.
(function(){
'use strict';
angular
.module('http-interceptor',[])
.config(config);
config.$inject = ['$provide', '$httpProvider'];
function config($provide, $httpProvider) {
$provide.factory('HttpInterceptor', httpInterceptor);
httpInterceptor.$inject = ['$q'];
function httpInterceptor($q) {
return {
request: onRequest,
response: onResponse,
requestError: onRequestError,
responseError: onResponseError
};
function onRequest(config){
console.log('config {} ', config);
return config;
};
function onResponse(response) {
console.log('response {} ', response);
return response;
};
function onRequestError(rejection) {
console.log('rejection {} ', rejection);
return $q.reject(rejection);
};
function onResponseError(rejection) {
console.log('rejection {} ', rejection);
return $q.reject(rejection);
};
};
$httpProvider.interceptors.push('HttpInterceptor');
};
}());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment