sendTransfer() does not throw if the plugin is stateful
dappelt opened this issue · 3 comments
LPI is defined in terms of Promises, so sendTransfer() should reject with an error, not throw an error.
From https://github.com/interledger/rfcs/blob/master/0004-ledger-plugin-interface/0004-ledger-plugin-interface.md#sendtransfer:
Rejects with InvalidFieldsError if required fields are missing from the transfer or malformed. Rejects with DuplicateIdError if a transfer with the given ID and different already exists. Rejects with InsufficientBalanceError if the transfer is rejected due to the source balance being too low. Rejects with AccountNotFoundError if the destination account does not exist. Rejects with NotAcceptedError if the transfer is otherwise rejected by the ledger.
Did you have a look at the source code? sendTransfer() is an async function. If an error is thrown from within an async function it is automatically returned to the caller as rejected promise. So speaking of "throwing an error" is correct in this context, but I have better things to do than changing the title back ;-)
ah right, my bad! When an async function is called, it returns a Promise.