Skip to content

Instantly share code, notes, and snippets.

@kfuchs
Created May 1, 2014 15:28
Show Gist options
  • Save kfuchs/f8a4aa48c8e7c8dc103e to your computer and use it in GitHub Desktop.
Save kfuchs/f8a4aa48c8e7c8dc103e to your computer and use it in GitHub Desktop.
Interceptor Example
App.config(function($httpProvider) {
var logsOutUserOn401 = function($location, $q, SessionService) {
var success = function(response) {
return response;
};
var error = function(response) {
if(response.status === 401) {
SessionService.unset('authenticated');
$location.path('/login');
}
return $q.reject(response);
};
return function(promise) {
return promise.then(success, error);
};
};
$httpProvider.responseInterceptors.push(logsOutUserOn401);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment