catch some errors on spark.
This commit is contained in:
parent
574358a118
commit
3215b5d2bb
1 changed files with 22 additions and 11 deletions
|
|
@ -1,7 +1,7 @@
|
||||||
import trio # type: ignore
|
import trio # type: ignore
|
||||||
import random
|
|
||||||
import json
|
import json
|
||||||
import httpx
|
import httpx
|
||||||
|
import random
|
||||||
from os import getenv
|
from os import getenv
|
||||||
from typing import Optional, AsyncGenerator
|
from typing import Optional, AsyncGenerator
|
||||||
|
|
||||||
|
|
@ -40,13 +40,16 @@ class SparkWallet(Wallet):
|
||||||
else:
|
else:
|
||||||
params = {}
|
params = {}
|
||||||
|
|
||||||
async with httpx.AsyncClient() as client:
|
try:
|
||||||
r = await client.post(
|
async with httpx.AsyncClient() as client:
|
||||||
self.url + "/rpc",
|
r = await client.post(
|
||||||
headers={"X-Access": self.token},
|
self.url + "/rpc",
|
||||||
json={"method": key, "params": params},
|
headers={"X-Access": self.token},
|
||||||
timeout=40,
|
json={"method": key, "params": params},
|
||||||
)
|
timeout=40,
|
||||||
|
)
|
||||||
|
except (OSError, httpx.ConnectError, httpx.RequestError) as exc:
|
||||||
|
raise SparkError("error connecting to spark: " + str(exc))
|
||||||
|
|
||||||
try:
|
try:
|
||||||
data = r.json()
|
data = r.json()
|
||||||
|
|
@ -143,7 +146,11 @@ class SparkWallet(Wallet):
|
||||||
return PaymentResponse(True, r["payment_hash"], fee_msat, preimage, None)
|
return PaymentResponse(True, r["payment_hash"], fee_msat, preimage, None)
|
||||||
|
|
||||||
async def get_invoice_status(self, checking_id: str) -> PaymentStatus:
|
async def get_invoice_status(self, checking_id: str) -> PaymentStatus:
|
||||||
r = await self.listinvoices(label=checking_id)
|
try:
|
||||||
|
r = await self.listinvoices(label=checking_id)
|
||||||
|
except (SparkError, UnknownError):
|
||||||
|
return PaymentStatus(None)
|
||||||
|
|
||||||
if not r or not r.get("invoices"):
|
if not r or not r.get("invoices"):
|
||||||
return PaymentStatus(None)
|
return PaymentStatus(None)
|
||||||
if r["invoices"][0]["status"] == "unpaid":
|
if r["invoices"][0]["status"] == "unpaid":
|
||||||
|
|
@ -160,7 +167,11 @@ class SparkWallet(Wallet):
|
||||||
return PaymentStatus(None)
|
return PaymentStatus(None)
|
||||||
|
|
||||||
# ask sparko
|
# ask sparko
|
||||||
r = await self.listpays(payment_hash=checking_id)
|
try:
|
||||||
|
r = await self.listpays(payment_hash=checking_id)
|
||||||
|
except (SparkError, UnknownError):
|
||||||
|
return PaymentStatus(None)
|
||||||
|
|
||||||
if not r["pays"]:
|
if not r["pays"]:
|
||||||
return PaymentStatus(False)
|
return PaymentStatus(False)
|
||||||
if r["pays"][0]["payment_hash"] == checking_id:
|
if r["pays"][0]["payment_hash"] == checking_id:
|
||||||
|
|
@ -184,7 +195,7 @@ class SparkWallet(Wallet):
|
||||||
data = json.loads(line[5:])
|
data = json.loads(line[5:])
|
||||||
if "pay_index" in data and data.get("status") == "paid":
|
if "pay_index" in data and data.get("status") == "paid":
|
||||||
yield data["label"]
|
yield data["label"]
|
||||||
except (OSError, httpx.ReadError):
|
except (OSError, httpx.ReadError, httpx.ConnectError):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
print("lost connection to spark /stream, retrying in 5 seconds")
|
print("lost connection to spark /stream, retrying in 5 seconds")
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue