From 9d3290cd9a4bf367fd75843b560d2b3c81666942 Mon Sep 17 00:00:00 2001 From: calle <93376500+callebtc@users.noreply.github.com> Date: Wed, 18 Jan 2023 12:02:32 +0100 Subject: [PATCH] fix: lntips payment lookup error handling (#1374) --- lnbits/wallets/lntips.py | 44 +++++++++++++++++++++++----------------- 1 file changed, 25 insertions(+), 19 deletions(-) diff --git a/lnbits/wallets/lntips.py b/lnbits/wallets/lntips.py index f0d08cf1e..92b33b7a5 100644 --- a/lnbits/wallets/lntips.py +++ b/lnbits/wallets/lntips.py @@ -113,31 +113,37 @@ class LnTipsWallet(Wallet): return PaymentResponse(True, checking_id, fee_msat, preimage, None) async def get_invoice_status(self, checking_id: str) -> PaymentStatus: - async with httpx.AsyncClient() as client: - r = await client.post( - f"{self.endpoint}/api/v1/invoicestatus/{checking_id}", - headers=self.auth, - ) + try: + async with httpx.AsyncClient() as client: + r = await client.post( + f"{self.endpoint}/api/v1/invoicestatus/{checking_id}", + headers=self.auth, + ) - if r.is_error or len(r.text) == 0: + if r.is_error or len(r.text) == 0: + raise Exception + + data = r.json() + return PaymentStatus(data["paid"]) + except: return PaymentStatus(None) - data = r.json() - return PaymentStatus(data["paid"]) - async def get_payment_status(self, checking_id: str) -> PaymentStatus: - async with httpx.AsyncClient() as client: - r = await client.post( - url=f"{self.endpoint}/api/v1/paymentstatus/{checking_id}", - headers=self.auth, - ) + try: + async with httpx.AsyncClient() as client: + r = await client.post( + url=f"{self.endpoint}/api/v1/paymentstatus/{checking_id}", + headers=self.auth, + ) - if r.is_error: + if r.is_error: + raise Exception + data = r.json() + + paid_to_status = {False: None, True: True} + return PaymentStatus(paid_to_status[data.get("paid")]) + except: return PaymentStatus(None) - data = r.json() - - paid_to_status = {False: None, True: True} - return PaymentStatus(paid_to_status[data.get("paid")]) async def paid_invoices_stream(self) -> AsyncGenerator[str, None]: last_connected = None