alby: fix balance reporting and error handling + opennode: fix error handling (#2221)

* opennode: fix error handling

* alby: fix balance reporting and error handling
This commit is contained in:
Pavol Rusnak 2024-02-06 05:26:50 -03:00 committed by GitHub
parent 22ea83e843
commit 4f45781319
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 10 additions and 5 deletions

View File

@ -44,11 +44,14 @@ class AlbyWallet(Wallet):
except (httpx.ConnectError, httpx.RequestError): except (httpx.ConnectError, httpx.RequestError):
return StatusResponse(f"Unable to connect to '{self.endpoint}'", 0) return StatusResponse(f"Unable to connect to '{self.endpoint}'", 0)
data = r.json()["balance"]
if r.is_error: if r.is_error:
return StatusResponse(data["error"], 0) error_message = r.json()["message"]
return StatusResponse(error_message, 0)
return StatusResponse(None, data) data = r.json()
assert data["unit"] == "sat"
# multiply balance by 1000 to get msats balance
return StatusResponse(None, data["balance"] * 1000)
async def create_invoice( async def create_invoice(
self, self,

View File

@ -56,10 +56,12 @@ class OpenNodeWallet(Wallet):
except (httpx.ConnectError, httpx.RequestError): except (httpx.ConnectError, httpx.RequestError):
return StatusResponse(f"Unable to connect to '{self.endpoint}'", 0) return StatusResponse(f"Unable to connect to '{self.endpoint}'", 0)
data = r.json()["data"]
if r.is_error: if r.is_error:
return StatusResponse(data["message"], 0) error_message = r.json()["message"]
return StatusResponse(error_message, 0)
data = r.json()["data"]
# multiply balance by 1000 to get msats balance
return StatusResponse(None, data["balance"]["BTC"] * 1000) return StatusResponse(None, data["balance"]["BTC"] * 1000)
async def create_invoice( async def create_invoice(