Skip to content

Instantly share code, notes, and snippets.

@JulienSansot
Created June 10, 2016 09:16
Show Gist options
  • Save JulienSansot/8bba78154ab5306516b72a9057c71b66 to your computer and use it in GitHub Desktop.
Save JulienSansot/8bba78154ab5306516b72a9057c71b66 to your computer and use it in GitHub Desktop.
intercept error in angular
(function(){
var httpInterceptor = function ($provide, $httpProvider) {
$provide.factory('httpInterceptor', function ($q) {
return {
response: function (response) {
return response || $q.when(response);
},
responseError: function (rejection) {
if(rejection.status === 401) {
// you are not autorized
}
return $q.reject(rejection);
}
};
});
$httpProvider.interceptors.push('httpInterceptor');
};
angular.module("dashboard").config(httpInterceptor);
}());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment