fix: add cln unspecified error code bolt11 error to errorcodes (#2503)

{'code': -32602, 'message': 'Invalid bolt11: Prefix bc is not for regtest'}```
This commit is contained in:
dni ⚡ 2024-05-16 09:59:54 +02:00 committed by GitHub
parent 5114bd4a47
commit 63ce506d29
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 10 additions and 5 deletions

View File

@ -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}"

View File

@ -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']}."