throw correct error if takeOffer() fails

This commit is contained in:
woodser 2024-01-05 15:01:36 -05:00
parent f34d380711
commit 6bd9f29063

View File

@ -1062,8 +1062,9 @@ export default class HavenoClient {
.setOfferId(offerId)
.setPaymentAccountId(paymentAccountId);
if (amount) request.setAmount(amount.toString());
HavenoUtils.log(0, "Taking offer with taker amount: " + amount);
return (await this._tradesClient.takeOffer(request, {password: this._password})).getTrade()!;
const resp = await this._tradesClient.takeOffer(request, {password: this._password});
if (resp.getTrade()) return resp.getTrade()!;
throw new HavenoError(resp.getFailureReason()?.getDescription()!, resp.getFailureReason()?.getAvailabilityResult());
} catch (e: any) {
throw new HavenoError(e.message, e.code);
}