Created
March 19, 2014 12:58
-
-
Save toamitkumar/9641101 to your computer and use it in GitHub Desktop.
Response interceptor for handling 401s
This file contains hidden or 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
.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