@@ -97,9 +97,11 @@ def exchange(bot, match):
9797 bot .reply ("Something went wrong while I was getting the exchange rate." )
9898 LOGGER .error ("Error in GET request: {}" .format (err ))
9999 return
100- except ValueError :
101- bot .reply ("Error: Got malformed data." )
102- LOGGER .error ("Invalid json on update_rates" )
100+ except (KeyError , ValueError ) as err :
101+ bot .reply ("Error: Could not update exchange rates. Try again later." )
102+ LOGGER .error ("{} on update_rates" .format (
103+ 'Invalid JSON' if type (err ).__name__ == 'ValueError' else 'Missing JSON value' ,
104+ ))
103105 return
104106 except FixerError as err :
105107 bot .reply ('Sorry, something went wrong with Fixer' )
@@ -191,7 +193,6 @@ def update_rates(bot):
191193
192194 response .raise_for_status ()
193195 rates_fiat = response .json ()
194- rates_updated = time .time ()
195196
196197 rates = rates_fiat ['rates' ]
197198 rates ['EUR' ] = 1.0 # Put this here to make logic easier
@@ -202,6 +203,10 @@ def update_rates(bot):
202203 if rate .upper () not in rates :
203204 rates [rate .upper ()] = rates_crypto ['rates' ][rate ]['value' ] * eur_btc_rate
204205
206+ # if an error aborted the operation prematurely, we want the next call to retry updating rates
207+ # therefore we'll update the stored timestamp at the last possible moment
208+ rates_updated = time .time ()
209+
205210
206211@plugin .command ('cur' , 'currency' , 'exchange' )
207212@plugin .example ('.cur 100 usd in btc cad eur' ,
0 commit comments