GUAC-1161: Reorganize authenticationInterceptor to match service pattern used elsewhere.

This commit is contained in:
Michael Jumper
2015-04-20 15:45:16 -07:00
parent 1010552c69
commit 999be47b20

View File

@@ -20,13 +20,29 @@
* THE SOFTWARE. * THE SOFTWARE.
*/ */
angular.module('index').factory('authenticationInterceptor', ['$location', '$q', angular.module('index').factory('authenticationInterceptor', ['$injector',
function authenticationInterceptor($location, $q) { function authenticationInterceptor($injector) {
return { // Required services
var $location = $injector.get('$location');
var $q = $injector.get('$q');
// Redirect users to login if authorization fails var service = {};
responseError: function handleErrorResponse(rejection) {
/**
* Redirect users to login if authorization fails. This is called
* automatically when this service is registered as an interceptor, as
* documented at:
*
* https://docs.angularjs.org/api/ng/service/$http#interceptors
*
* @param {HttpPromise} rejection
* The promise associated with the HTTP request that failed.
*
* @returns {Promise}
* A rejected promise containing the originally-rejected HttpPromise.
*/
service.responseError = function responseError(rejection) {
// Only redirect failed authentication requests // Only redirect failed authentication requests
if ((rejection.status === 401 || rejection.status === 403) if ((rejection.status === 401 || rejection.status === 403)
@@ -40,8 +56,8 @@ angular.module('index').factory('authenticationInterceptor', ['$location', '$q',
return $q.reject(rejection); return $q.reject(rejection);
}
}; };
return service;
}]); }]);