0
私は401エラーのためのresponseErrorハンドラを持っています。 HTTPインターセプタは、HTTP要求を認証して再試行を継続するようにモーダルユーザに要求します。しかし、問題は、2つ以上のモーダルが表示されているリクエストインターセプタに複数の失敗があり、数回認証する必要がある場合です。どのように私は最初の要求で認証された後にすべてのHTTP要求を再試行できますか?
$httpProvider.interceptors.push(function($q, $injector, Auth) {
return {
responseError: function(rejection) {
if (rejection.status === 401) {
return Auth.authenticate().then(function() {
return $injector.get('$http')(rejection.config);
});
}
return $q.reject(rejection);
}
};
});
.factory('Auth', function($injector) {
return {
authenticate: function() {
var $uibModal = $injector.get('$uibModal');
var modal = $uibModal.open({
templateUrl: '/authenticateModal.html',
controller: 'AuthenticateModalController',
});
return modal.result.then(function() {
// success
});
}
}
});
.controller('AuthenticateModalController', function ($scope, $uibModalInstance, $http, Auth) {
$scope.submit = function() {
Auth.login({
'email': $scope.email,
'password': $scope.password
}).then(function successCallback(response) {
$uibModalInstance.close();
}, function errorCallback(response) {
console.log('error');
});
};
})
は、約束を棄却し、モーダル? – tyler
@タイラー、モーダルが追加されました。あなたはすべての要求が失敗し、それは私と一緒にうまくいかない場合、拒否された約束の原因を必要としません。 – user256968