首页 > 解决方案 > 错误时打破承诺链执行[重复]

问题描述

当它失败时,我试图打破承诺链执行,但它仍然编译链,但是,在特定方法中发生了错误。

this.addParticipantByEmail(email, type)
        .then(() => this.issueIdentity(email, type))
        .then(cardData => this.dataService.importWallet(cardData))
        .then(() => this.authService.signupUser(email, password, type))
        .then( () => {
          this.spinner.hide();
        })
        .catch(error => {
          if (error === "Server error") {
            return (this.errorMessage =
              "Could not connect to REST server. Please check your configuration details");
          } else {
            return (this.errorMessage = error);
          }
        });


addParticipantByEmail(email: string, type: string): Promise<any> {
    this.initiateParticipant(email, type);
    // Add the participant using the admin account to the Blockchain through COMPOSER-REST-API
    return this.service
      .addParticipantAsAdmin(this.participant)
      .toPromise()
      .catch(error => {
        if (error === "Server error") {
          this.errorMessage =
            "Could not connect to REST server. Please check your configuration details";
        } else {
          this.errorMessage = error;
        }
      });
  }

当其中一个承诺发生错误时,我想停止承诺链。

标签: javascriptangularpromise

解决方案


推荐阅读