Skip to content

Instantly share code, notes, and snippets.

@toamitkumar
Created March 19, 2014 12:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save toamitkumar/9641101 to your computer and use it in GitHub Desktop.
Save toamitkumar/9641101 to your computer and use it in GitHub Desktop.
Response interceptor for handling 401s
.config(function ($httpProvider) {
var logsOutUserOn401 = ['$q', '$location', function ($q, $location) {
var success = function (response) {
return response;
};
var error = function (response) {
if (response.status === 401) {
//redirect them back to login page
$location.path('/s/login');
return $q.reject(response);
}
else {
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