Commit 6395109e authored by Bruno Duyé's avatar Bruno Duyé

Add exception managing around API json decoding

parent 2daa7adb
......@@ -134,10 +134,16 @@ def get_from_api(url, raise_on_errors=True):
log.debug(url)
response = requests_session.get(url)
content_str = response.content
try:
content_dict = json.loads(content_str)
except Exception as e:
log.exception("API call: {!r}\nException during conversion of API result to json. Result saved to last_api_result.json file.".format(url))
with open('last_api_result.json', 'wb') as _f:
_f.write(content_str)
raise e
if debug_mode:
with open('last_api_result.json', 'wb') as _f:
_f.write(content_str)
content_dict = json.loads(content_str)
error = raise_or_log_if_error(content_dict['BEAAPI'])
if error:
return None
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment