Forked from jordanmkoncz/auth-interceptor.service.js
Created
October 28, 2015 12:50
-
-
Save genbliz/e7ae527a5edce70764a4 to your computer and use it in GitHub Desktop.
Avoid AngularJS circular dependency error when using $state in a HTTP interceptor
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('app') | |
.factory('AuthInterceptor', AuthInterceptor); | |
function AuthInterceptor($injector, $q) { | |
var $state; | |
var service = { | |
responseError: responseError | |
}; | |
return service; | |
function responseError(rejection) { | |
$state = $state || $injector.get('$state'); | |
if (rejection.status === 401 && rejection.config.url !== '/login') { | |
$state.go('login'); | |
} | |
return $q.reject(rejection); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment