Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angularjs 重试后如何继续承诺链?_Angularjs_Angular Promise_Restangular - Fatal编程技术网

Angularjs 重试后如何继续承诺链?

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

我使用restangular对后端进行多次调用,我依赖于第一次调用的结果来执行后续调用

我正在尝试设置重试逻辑,以便在重试成功后执行后续请求。以下是我目前的代码:

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数组,然后以这种方式重试它