From ddab4075d262d5903a28136a1419f5afa929645c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?dni=20=E2=9A=A1?= Date: Wed, 21 Feb 2024 10:43:34 +0100 Subject: [PATCH] fix: raise proper exception in services pay_invoice also values where checked twice --- lnbits/core/services.py | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/lnbits/core/services.py b/lnbits/core/services.py index 95e170cdb..52a576340 100644 --- a/lnbits/core/services.py +++ b/lnbits/core/services.py @@ -189,12 +189,15 @@ async def pay_invoice( If the payment is still in flight, we hope that some other process will regularly check for the payment. """ - invoice = bolt11_decode(payment_request) + try: + invoice = bolt11_decode(payment_request) + except Exception: + raise InvoiceFailure("Bolt11 decoding failed.") if not invoice.amount_msat or not invoice.amount_msat > 0: - raise ValueError("Amountless invoices not supported.") + raise InvoiceFailure("Amountless invoices not supported.") if max_sat and invoice.amount_msat > max_sat * 1000: - raise ValueError("Amount in invoice is too high.") + raise InvoiceFailure("Amount in invoice is too high.") await check_wallet_limits(wallet_id, conn, invoice.amount_msat) @@ -202,11 +205,6 @@ async def pay_invoice( temp_id = invoice.payment_hash internal_id = f"internal_{invoice.payment_hash}" - if invoice.amount_msat == 0: - raise ValueError("Amountless invoices not supported.") - if max_sat and invoice.amount_msat > max_sat * 1000: - raise ValueError("Amount in invoice is too high.") - _, extra = await calculate_fiat_amounts( invoice.amount_msat / 1000, wallet_id, extra=extra, conn=conn )