From e2099b1c82c74d1c1a4caee0b94cdfb588e0917f Mon Sep 17 00:00:00 2001 From: Mark Veidemanis Date: Tue, 28 Dec 2021 11:57:18 +0000 Subject: [PATCH] Better error handling in total command --- handler/irc.py | 8 +++++--- handler/revolut.py | 2 ++ 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/handler/irc.py b/handler/irc.py index b129d21..b2298d1 100644 --- a/handler/irc.py +++ b/handler/irc.py @@ -104,12 +104,12 @@ class IRCBot(irc.IRCClient): try: int(spl[2]) except ValueError: - self.msg(channel, "Amount is not an integer") + self.msg(channel, "Amount is not an integer.") rtrn = self.tx.find_tx(spl[1], spl[2]) if rtrn == "AMOUNT_INVALID": - self.msg(channel, "Reference found but amount invalid") + self.msg(channel, "Reference found but amount invalid.") elif not rtrn: - self.msg(channel, "Reference not found") + self.msg(channel, "Reference not found.") else: return dumps(rtrn) @@ -121,6 +121,8 @@ class IRCBot(irc.IRCClient): elif cmd == "total" and host in self.admins: total_usd = self.revolut.get_total_usd() + if not total_usd: + self.msg(channel, "Error getting total balance.") self.msg(channel, f"Total: {round(total_usd, 2)}USD") def signedOn(self): diff --git a/handler/revolut.py b/handler/revolut.py index 235c292..5410033 100644 --- a/handler/revolut.py +++ b/handler/revolut.py @@ -189,6 +189,8 @@ class Revolut(object): def get_total_usd(self): rates = self.agora.get_rates_all() accounts = self.accounts() + if not accounts: + return False total_usd = 0 for account in accounts: if account["currency"] == "USD":