Browse Source

fix: don't call `r.json()` until we know we have a response

fee_issues
Eneko Illarramendi 5 years ago
parent
commit
4c739dbb90
  1. 11
      lnbits/wallets/lntxbot.py

11
lnbits/wallets/lntxbot.py

@ -37,9 +37,13 @@ class LntxbotWallet(Wallet):
def get_invoice_status(self, payment_hash: str, wait: bool = True) -> TxStatus:
wait = "true" if wait else "false"
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()
if not r.ok or "error" in data:
if "error" in data:
return TxStatus(r, None)
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:
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, {"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…
Cancel
Save