Merge pull request #1107 from pgrodrigues/master

fix(core): Remove duplicate angular interceptor
This commit is contained in:
Cody B. Daig
2015-12-28 19:41:24 -08:00
3 changed files with 8 additions and 33 deletions

View File

@@ -1,12 +1,14 @@
'use strict';
angular.module('core').factory('authInterceptor', ['$q', '$injector',
function ($q, $injector) {
angular.module('core').factory('authInterceptor', ['$q', '$injector', 'Authentication',
function ($q, $injector, Authentication) {
return {
responseError: function(rejection) {
if (!rejection.config.ignoreAuthModule) {
switch (rejection.status) {
case 401:
// Deauthenticate the global user
Authentication.user = null;
$injector.get('$state').transitionTo('authentication.signin');
break;
case 403:

View File

@@ -6,6 +6,7 @@
var authInterceptor,
$q,
$state,
Authentication,
httpProvider;
// Load the main application module
@@ -16,10 +17,11 @@
httpProvider = $httpProvider;
}));
beforeEach(inject(function(_authInterceptor_, _$q_, _$state_) {
beforeEach(inject(function(_authInterceptor_, _$q_, _$state_, _Authentication_) {
authInterceptor = _authInterceptor_;
$q = _$q_;
$state = _$state_;
Authentication = _Authentication_;
spyOn($q,'reject');
spyOn($state,'transitionTo');
}));
@@ -56,6 +58,7 @@
};
var promise = authInterceptor.responseError(response);
expect($q.reject).toHaveBeenCalled();
expect(Authentication.user).toBe(null);
expect($state.transitionTo).toHaveBeenCalledWith('authentication.signin');
});
});

View File

@@ -1,30 +0,0 @@
'use strict';
// Config HTTP Error Handling
angular.module('users').config(['$httpProvider',
function ($httpProvider) {
// Set the httpProvider "not authorized" interceptor
$httpProvider.interceptors.push(['$q', '$location', 'Authentication',
function ($q, $location, Authentication) {
return {
responseError: function (rejection) {
switch (rejection.status) {
case 401:
// Deauthenticate the global user
Authentication.user = null;
// Redirect to signin page
$location.path('signin');
break;
case 403:
// Add unauthorized behaviour
break;
}
return $q.reject(rejection);
}
};
}
]);
}
]);