Created
April 17, 2014 19:26
-
-
Save jkuchynka/11006322 to your computer and use it in GitHub Desktop.
angular401interceptor
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
angular.module('angularAuth', ['ngCookies']) | |
.config([ | |
'$routeProvider', | |
'$locationProvider', | |
'$httpProvider', | |
function ($routeProvider, $locationProvider, $httpProvider) { | |
// ... | |
var interceptor = ['$location', '$q', function($location, $q) { | |
function success(response) { | |
return response; | |
} | |
function error(response) { | |
if(response.status === 401) { | |
// Or login dialog | |
$location.path('/login'); | |
return $q.reject(response); | |
} | |
else { | |
return $q.reject(response); | |
} | |
} | |
return function(promise) { | |
return promise.then(success, error); | |
} | |
}]; | |
$httpProvider.responseInterceptors.push(interceptor); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment