Created
May 1, 2014 15:28
-
-
Save kfuchs/f8a4aa48c8e7c8dc103e to your computer and use it in GitHub Desktop.
Interceptor Example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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