From b7791d284569daf8cdf1be8e4aa6632720758d08 Mon Sep 17 00:00:00 2001 From: belikor Date: Tue, 13 Jul 2021 11:54:14 -0500 Subject: [PATCH] exchange_rate_manager: raise exception if `'error'` is in `json_response` If the error is not handled, the running daemon will continuously print the following error message: ``` Traceback (most recent call last): File "lbry/extras/daemon/exchange_rate_manager.py", line 77, in get_rate File "lbry/extras/daemon/exchange_rate_manager.py", line 189, in get_rate_from_response KeyError: 0 ``` This started happening when the UPBit exchange decided to delist the LBC coin. Normally `json_response` should be a dictionary, not a list, so `json_response[0]` causes an error. By checking for the `'error'` key, we can raise the proper exception. Once this is done, the message will be a warning, not a traceback. ``` WARNING lbry.extras.daemon.exchange_rate_manager:92: Failed to get exchange rate from UPbit: result not found ``` --- lbry/extras/daemon/exchange_rate_manager.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lbry/extras/daemon/exchange_rate_manager.py b/lbry/extras/daemon/exchange_rate_manager.py index a80f50575..500c6f24e 100644 --- a/lbry/extras/daemon/exchange_rate_manager.py +++ b/lbry/extras/daemon/exchange_rate_manager.py @@ -186,7 +186,7 @@ class UPbitBTCFeed(MarketFeed): params = {"markets": "BTC-LBC"} def get_rate_from_response(self, json_response): - if len(json_response) != 1 or 'trade_price' not in json_response[0]: + if "error" in json_response or len(json_response) != 1 or 'trade_price' not in json_response[0]: raise InvalidExchangeRateResponseError(self.name, 'result not found') return 1.0 / float(json_response[0]['trade_price'])