Angularjs 重试后如何继续承诺链?
我使用restangular对后端进行多次调用,我依赖于第一次调用的结果来执行后续调用 我正在尝试设置重试逻辑,以便在重试成功后执行后续请求。以下是我目前的代码:Angularjs 重试后如何继续承诺链?,angularjs,angular-promise,restangular,Angularjs,Angular Promise,Restangular,我使用restangular对后端进行多次调用,我依赖于第一次调用的结果来执行后续调用 我正在尝试设置重试逻辑,以便在重试成功后执行后续请求。以下是我目前的代码: reefService.createGitLabProject(formData) .then(function(apiResponse) { $scope.apiStatus.messages.push({'direction': 'in', 'body': apiResponse.result}); $scop
reefService.createGitLabProject(formData)
.then(function(apiResponse) {
$scope.apiStatus.messages.push({'direction': 'in', 'body': apiResponse.result});
$scope.progressValue += 1;
var gitLabProject = {
'id': apiResponse.data.id,
'http_url_to_repo': apiResponse.data.http_url_to_repo,
'ssh_url_to_repo': apiResponse.data.ssh_url_to_repo
};
// add deploy key
reefService.addGitLabDeployKey(gitLabProject)
.then(function(apiResponse) {
$scope.apiStatus.messages.push({'direction': 'in', 'body': apiResponse.result});
$scope.progressValue += 1;
})
.catch(function(apiError) {
$scope.apiStatus.errors.push(apiError);
});
// add web hook
reefService.addGitLabProjectHook(gitLabProject)
.then(function(apiResponse) {
$scope.apiStatus.messages.push({'direction': 'in', 'body': apiResponse.result});
$scope.progressValue += 1;
})
.catch(function(apiError) {
$scope.apiStatus.errors.push(apiError);
});
// failed to create project
})
.catch(function(apiError) {
$scope.apiStatus.errors.push(apiError);
});
重试被手动调用,它将从$scope.apiStatus.errors
中传递apirerror
重新启动Angular对象。我正在使用以下命令:
$scope.retryRequest = function(error){
var restAngularConf = error.config;
$http(restAngularConf)
.then(function(apiResponse) {
$scope.progressValue += 1;
// add response to messages
$scope.apiStatus.messages.push({'direction': 'in', 'body': apiResponse.data.result});
// delete error from errors array
var ix = $scope.apiStatus.errors.indexOf(error);
$scope.apiStatus.errors.splice(ix, 1);
})
.catch(function(apiError) {
toaster.pop('error', 'Retry Error', apiError.data.message);
});
};
它基本上接收apiError
,并使用apiError.config
(url、post数据等)中的数据运行$http
调用。这适用于没有依赖项的调用,如addGitLabDeployKey
和addGitLabProjectHook
,我很难确定如何设置createGitLabProject
,以便在其错误传递到$scope.retryRequest
并完成请求后,addGitLabDeployKey
和addGitLabProjectHook
继续
如何在createGitLabProject
中设置$q
服务,以便请求链在重试后继续
非常感谢你的帮助 看来我没有抓住承诺的重点,我需要将其包装在函数中,并将函数传递给retry数组,然后以这种方式重试它