grumpitect / SAGA

A Distributed Transaction Library based on Node.js and MongoDB
23 stars 6 forks source link

Throw exception after rollback #1

Open xfg opened 5 years ago

xfg commented 5 years ago

I think that we should throw exception after successful or unsuccessful rollback so that the client have a possibility handle this exception because now I don't know where the error is occurred and can not log this error. The library should be more verbose.

grumpitect commented 5 years ago

There is a way for the client to know the Saga's execution results...here is an example:

    const result = await sagaService.sagas.editOrder.execute({
      params,
      keys,
      stopKeys,
      waitInsteadOfStop: true,
    });

    if (result.duplicateKey) {
      throw EditOrderError.DUPLICATE;
    } else if (result.isRollback) {
      const {
        error,
      } = result.params.flow.transactionError;

      throw error;
    }

    const {
      isOrderSuccessfullyEdited,
      requireOnlinePayment,
      paymentUrl,
      orderNumber,
      changedProviderList,
      isDeliveryTimeChanged,
      isAddressChanged,
      isPaymentMethodChanged,
    } = result.params.transactionValues;

I agree that we need more documentation and/or better API design, but for the moment we don't have any contributors. It would help if you decide to opt in...

xfg commented 5 years ago

Thanks for the reply. It solve my problem. I think it's worth to publish the library to npm because now I need to install the library right from the master branch what is not good and may also attract some audience to the library.