Skip to content
Advertisement

await operator is being skipped

Could you please help me with an issue I am facing?

I have attached my code below, after button click, it catches an error (if there is) but skips

await this.reloadGridsOnAction(contractItemSubSystemIDsList, responce, true);

Which means it just jumps to catch (e). I need it to reload my grid first. Thank you for any advise.

private async onAssignClick() {
  this.isChangeAssociationInProcess$.next(true);
  const ac = this.activeContractCell$.getValue()!;
  const PostAwardContractID = getColumnValue(ac.record, PropNames.PostAwardContractID);
  const { contractItemSubSystemIDsList, ContractItemSubSystemIDsMap } = this.prepareUpdateLists(true);

  const body = {
    ContractItemSubSystemIDsList: ContractItemSubSystemIDsMap,
    PostAwardContractID,
    IsFromCWP: +(this.currentItemsModeId$.getValue() === ItemsMode.CWP)
  };

  try {
    await ModalSpinner.instance.show("Assigning", async () => {
      const responce = await ErrorHandler.executeWithHandling(() => HttpService.instance.post(assignmentsUrl, body).asJson<Array<{
        [PropNames.ModuleItemID]: number,
        [PropNames.ConstructionSubSystemID]: number
      }>>());

      await this.reloadGridsOnAction(contractItemSubSystemIDsList, responce, true);
    });

    return true;
  } catch (e) {
    if (!e.isConflict) throw e;
    const response = await (e.response as HttpResponse).asJson<any>(true);

    return ModalChannelService.instance.confirm(
      `ASSIGN ITEMS`,
      (
        <div className="delete-modal-content">
          <p className="modal-question">{response.Message}</p>
          <div className="distribution-board">
            <div className="text-ellipsis">Please refresh the page to see correct values.</div>
          </div>
        </div>
      ),
      [
        { returnValue: false, content: "CANCEL" },
      ],
      "assign-subsystems-modal"
    );
  }
}

Advertisement

Answer

If it skips over your code like that, chances are it threw an error and went straight into the catch.

If you want to always execute this block

await this.reloadGridsOnAction(contractItemSubSystemIDsList, responce, true);

you might want to have a finally block after the catch.

User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement