fix: don't call r.json() until we know we have a response
This commit is contained in:
parent
0d517b884a
commit
4c739dbb90
1 changed files with 7 additions and 4 deletions
|
|
@ -37,9 +37,13 @@ class LntxbotWallet(Wallet):
|
||||||
def get_invoice_status(self, payment_hash: str, wait: bool = True) -> TxStatus:
|
def get_invoice_status(self, payment_hash: str, wait: bool = True) -> TxStatus:
|
||||||
wait = "true" if wait else "false"
|
wait = "true" if wait else "false"
|
||||||
r = post(url=f"{self.endpoint}/invoicestatus/{payment_hash}?wait={wait}", headers=self.auth_invoice)
|
r = post(url=f"{self.endpoint}/invoicestatus/{payment_hash}?wait={wait}", headers=self.auth_invoice)
|
||||||
|
|
||||||
|
if not r.ok:
|
||||||
|
return TxStatus(r, None)
|
||||||
|
|
||||||
data = r.json()
|
data = r.json()
|
||||||
|
|
||||||
if not r.ok or "error" in data:
|
if "error" in data:
|
||||||
return TxStatus(r, None)
|
return TxStatus(r, None)
|
||||||
|
|
||||||
if "preimage" not in data or not data["preimage"]:
|
if "preimage" not in data or not data["preimage"]:
|
||||||
|
|
@ -49,9 +53,8 @@ class LntxbotWallet(Wallet):
|
||||||
|
|
||||||
def get_payment_status(self, payment_hash: str) -> TxStatus:
|
def get_payment_status(self, payment_hash: str) -> TxStatus:
|
||||||
r = post(url=f"{self.endpoint}/paymentstatus/{payment_hash}", headers=self.auth_invoice)
|
r = post(url=f"{self.endpoint}/paymentstatus/{payment_hash}", headers=self.auth_invoice)
|
||||||
data = r.json()
|
|
||||||
|
|
||||||
if not r.ok or "error" in data:
|
if not r.ok or "error" in r.json():
|
||||||
return TxStatus(r, None)
|
return TxStatus(r, None)
|
||||||
|
|
||||||
return TxStatus(r, {"complete": True, "failed": False, "unknown": None}[data.get("status", "unknown")])
|
return TxStatus(r, {"complete": True, "failed": False, "unknown": None}[r.json().get("status", "unknown")])
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue