|
87 | 87 | // page route event |
88 | 88 | //================================================ |
89 | 89 | $rootScope.pageViewLoading = false; |
| 90 | + |
90 | 91 | $rootScope.$on('$stateChangeStart', function (event, next, current) { |
91 | 92 | if (!_(routesThatRequireAuth).contains($location.path()) && !authenticationService.check()) { |
92 | 93 | console.log('Oops! please login!'); |
|
130 | 131 | } |
131 | 132 |
|
132 | 133 | }) |
133 | | - .run(function ($location, authenticationService, localStorageService, $timeout, Restangular, $http, $q) { |
| 134 | + .run(function ($location, authenticationService, localStorageService, $timeout, Restangular, $http, $q, $state) { |
134 | 135 |
|
135 | 136 | var refreshAccessToken = function () { |
136 | 137 | var deferred = $q.defer(); |
|
154 | 155 | }; |
155 | 156 |
|
156 | 157 | Restangular.setErrorInterceptor(function (response, deferred, responseHandler) { |
157 | | - if (response.status === 401 || response.message === 'token_expired') { |
| 158 | + if (response.data.message === 'token_invalid') { |
| 159 | + localStorageService.remove('token'); |
| 160 | + $state.go('fullscreen.login'); |
| 161 | + return false; |
| 162 | + } |
| 163 | + |
| 164 | + if (response.data.message === 'token_expired') { |
158 | 165 | return refreshAccessToken().then(function () { |
159 | 166 | response.config.headers.Authorization = authenticationService.getToken(); |
160 | 167 | // Repeat the request and then call the handlers the usual way. |
161 | 168 | $http(response.config).then(responseHandler, deferred.reject); |
162 | 169 | return false; |
163 | 170 | // Be aware that no request interceptors are called this way. |
164 | 171 | }); |
165 | | - return false; // error handled |
| 172 | + return false; |
166 | 173 | } |
167 | 174 | console.log('error not handled'); |
168 | 175 | return true; // error not handled |
|
0 commit comments