я изо всех сил пытаюсь найти способ перенаправить в состояние, когда возникает ошибка. Я обрабатываю ответы об ошибках с помощью setErrorInterceptor
Restangular следующим образом:
angular.module('app.http').factory('RestangularCustom',RestangularCustom);
RestangularCustom.$inject = ['Restangular','HandlerBag','$state','notify'];
function RestangularCustom(Restangular,HandlerBag,$state,notify) {
Restangular.setErrorInterceptor(function(response, deferred, responseHandler) {
// Add the error to the handler bag
HandlerBag.catchError(response);
// User can't access if already authenticated
if (response.status === 403 && response.data.response && response.data.response.auth === true) {
console.log('authenticated'); // it trigger correctly
$state.go('app.home');
return false;
}
if (response.status === 403 && response.data.context === 'authentication') {
console.log('auth error'); // it trigger correctly
$state.go('auth.login');
return false;
}
else {
notify({
classes: 'error',
message: response.data.message || 'Server Error'
});
}
return true; // error not handled
});
}
Следующий код правильно обрабатывает ошибки, запуская console.log()
, но не перенаправляя в мои разыскиваемые состояния.
Я прочитал следующий уже опубликованный вопрос:
URL-адрес изменения AngularJS в module.config
предлагается установить setErrorInterceptor
в функции run
, я тоже безуспешно пробовал, он тоже не перенаправляет. Что с этим не так?
$location.path('/app/home');
? - person Pankaj Parkar   schedule 20.03.2015