Skip to content

Commit 9997381

Browse files
author
Mark
committed
jet error handle
1 parent 3cab567 commit 9997381

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

backend/src/app/index.js

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@
8787
// page route event
8888
//================================================
8989
$rootScope.pageViewLoading = false;
90+
9091
$rootScope.$on('$stateChangeStart', function (event, next, current) {
9192
if (!_(routesThatRequireAuth).contains($location.path()) && !authenticationService.check()) {
9293
console.log('Oops! please login!');
@@ -130,7 +131,7 @@
130131
}
131132

132133
})
133-
.run(function ($location, authenticationService, localStorageService, $timeout, Restangular, $http, $q) {
134+
.run(function ($location, authenticationService, localStorageService, $timeout, Restangular, $http, $q, $state) {
134135

135136
var refreshAccessToken = function () {
136137
var deferred = $q.defer();
@@ -154,15 +155,21 @@
154155
};
155156

156157
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') {
158165
return refreshAccessToken().then(function () {
159166
response.config.headers.Authorization = authenticationService.getToken();
160167
// Repeat the request and then call the handlers the usual way.
161168
$http(response.config).then(responseHandler, deferred.reject);
162169
return false;
163170
// Be aware that no request interceptors are called this way.
164171
});
165-
return false; // error handled
172+
return false;
166173
}
167174
console.log('error not handled');
168175
return true; // error not handled

0 commit comments

Comments
 (0)