From eb31bfdf2e706df5844cdc7dbf06880fb681f5f9 Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Tue, 15 Dec 2020 15:16:58 +1030 Subject: [PATCH] currencyconvert: raise more meaningful exception on unknown currencies. Signed-off-by: Rusty Russell --- currencyrate/currencyrate.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/currencyrate/currencyrate.py b/currencyrate/currencyrate.py index 0580436..44f0e1b 100755 --- a/currencyrate/currencyrate.py +++ b/currencyrate/currencyrate.py @@ -95,7 +95,10 @@ def currencyrate(plugin, currency): @plugin.method("currencyconvert") def currencyconvert(plugin, amount, currency): """Converts currency using given APIs.""" - val = statistics.median([m.millisatoshis for m in get_rates(plugin, currency.upper()).values()]) * float(amount) + rates = get_rates(plugin, currency.upper()) + if len(rates) == 0: + raise Exception("No values available for currency {}".format(currency.upper())) + val = statistics.median([m.millisatoshis for m in rates.values()]) * float(amount) return {"msat": Millisatoshi(round(val))}