Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@mariojunior
Created August 7, 2013 16:36
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mariojunior/6175736 to your computer and use it in GitHub Desktop.
Save mariojunior/6175736 to your computer and use it in GitHub Desktop.
AngularJS Learned Lessons #1: - Getting a Invalid Session State on response and trait it.
//Intercepting a Invalid Session status using an Interceptor:
//Following the sample described in http://docs.angularjs.org/api/ng.$http (see "Response inteceptors" paragraph)
//At error function handler:
function (response) {
//if the user's session is invalid, then the status code is zero.
if (response.status == 0) {
//Session Invalid! So, you can do anything... typically, you can dispatch a custom event to be handled by some controller
//and manipulate your models ou routing state.
$rootScope.$emit('redirect_event');
return;
}
return $q.reject(response);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment