From 63ce506d2967a17353834ea31be45a122409a546 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?dni=20=E2=9A=A1?= Date: Thu, 16 May 2024 09:59:54 +0200 Subject: [PATCH] fix: add cln unspecified error code bolt11 error to errorcodes (#2503) {'code': -32602, 'message': 'Invalid bolt11: Prefix bc is not for regtest'}``` --- lnbits/wallets/corelightning.py | 8 +++++--- lnbits/wallets/corelightningrest.py | 7 +++++-- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/lnbits/wallets/corelightning.py b/lnbits/wallets/corelightning.py index 4dfbd5ed..8bc7096f 100644 --- a/lnbits/wallets/corelightning.py +++ b/lnbits/wallets/corelightning.py @@ -47,13 +47,15 @@ class CoreLightningWallet(Wallet): self.supports_description_hash = "deschashonly" in command # https://docs.corelightning.org/reference/lightning-pay + # -32602: Invalid bolt11: Prefix bc is not for regtest + # -1: Catchall nonspecific error. # 201: Already paid # 203: Permanent failure at destination. # 205: Unable to find a route. # 206: Route too expensive. # 207: Invoice expired. # 210: Payment timed out without a payment in progress. - self.pay_failure_error_codes = [201, 203, 205, 206, 207, 210] + self.pay_failure_error_codes = [-32602, 201, 203, 205, 206, 207, 210] # check last payindex so we can listen from that point on self.last_pay_index = 0 @@ -164,8 +166,8 @@ class CoreLightningWallet(Wallet): except RpcError as exc: logger.warning(exc) try: - error_code = exc.error.get("code") - if error_code in self.pay_failure_error_codes: # type: ignore + error_code = exc.error.get("code") # type: ignore + if error_code in self.pay_failure_error_codes: error_message = exc.error.get("message", error_code) # type: ignore return PaymentResponse( False, None, None, None, f"Payment failed: {error_message}" diff --git a/lnbits/wallets/corelightningrest.py b/lnbits/wallets/corelightningrest.py index 00a199d0..50a4ac52 100644 --- a/lnbits/wallets/corelightningrest.py +++ b/lnbits/wallets/corelightningrest.py @@ -50,13 +50,15 @@ class CoreLightningRestWallet(Wallet): } # https://docs.corelightning.org/reference/lightning-pay + # -32602: Invalid bolt11: Prefix bc is not for regtest + # -1: Catchall nonspecific error. # 201: Already paid # 203: Permanent failure at destination. # 205: Unable to find a route. # 206: Route too expensive. # 207: Invoice expired. # 210: Payment timed out without a payment in progress. - self.pay_failure_error_codes = [201, 203, 205, 206, 207, 210] + self.pay_failure_error_codes = [-32602, 201, 203, 205, 206, 207, 210] self.cert = settings.corelightning_rest_cert or False self.client = httpx.AsyncClient(verify=self.cert, headers=headers) @@ -204,7 +206,8 @@ class CoreLightningRestWallet(Wallet): try: logger.debug(exc) data = exc.response.json() - if data["error"]["code"] in self.pay_failure_error_codes: # type: ignore + error_code = int(data["error"]["code"]) + if error_code in self.pay_failure_error_codes: error_message = f"Payment failed: {data['error']['message']}" return PaymentResponse(False, None, None, None, error_message) error_message = f"REST failed with {data['error']['message']}."