catch JSONDecodeError in exchange rate manager

This commit is contained in:
Jack Robison 2019-12-11 10:54:59 -05:00
parent af7c20e440
commit c0439b7aa6
No known key found for this signature in database
GPG key ID: DF25C68FE0239BB2

View file

@ -106,7 +106,10 @@ class BittrexFeed(MarketFeed):
)
def _handle_response(self, response):
json_response = json.loads(response)
try:
json_response = json.loads(response)
except (ValueError, json.JSONDecodeError):
raise InvalidExchangeRateResponseError(self.name, "invalid rate response : %s" % response)
if 'result' not in json_response:
raise InvalidExchangeRateResponseError(self.name, 'result not found')
trades = json_response['result']
@ -131,7 +134,10 @@ class LBRYioFeed(MarketFeed):
)
def _handle_response(self, response):
json_response = json.loads(response)
try:
json_response = json.loads(response)
except (ValueError, json.JSONDecodeError):
raise InvalidExchangeRateResponseError(self.name, "invalid rate response : %s" % response)
if 'data' not in json_response:
raise InvalidExchangeRateResponseError(self.name, 'result not found')
return 1.0 / json_response['data']['lbc_btc']
@ -150,7 +156,7 @@ class LBRYioBTCFeed(MarketFeed):
def _handle_response(self, response):
try:
json_response = json.loads(response)
except ValueError:
except (ValueError, json.JSONDecodeError):
raise InvalidExchangeRateResponseError(self.name, "invalid rate response : %s" % response)
if 'data' not in json_response:
raise InvalidExchangeRateResponseError(self.name, 'result not found')
@ -170,7 +176,7 @@ class CryptonatorBTCFeed(MarketFeed):
def _handle_response(self, response):
try:
json_response = json.loads(response)
except ValueError:
except (ValueError, json.JSONDecodeError):
raise InvalidExchangeRateResponseError(self.name, "invalid rate response")
if 'ticker' not in json_response or len(json_response['ticker']) == 0 or \
'success' not in json_response or json_response['success'] is not True:
@ -191,7 +197,7 @@ class CryptonatorFeed(MarketFeed):
def _handle_response(self, response):
try:
json_response = json.loads(response)
except ValueError:
except (ValueError, json.JSONDecodeError):
raise InvalidExchangeRateResponseError(self.name, "invalid rate response")
if 'ticker' not in json_response or len(json_response['ticker']) == 0 or \
'success' not in json_response or json_response['success'] is not True: