Skip to content

Commit

Permalink
adding fix for api catch when response is not json
Browse files Browse the repository at this point in the history
  • Loading branch information
havok2063 committed Nov 22, 2021
1 parent 58b0c7f commit 9e32476
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion python/brain/api/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -224,8 +224,15 @@ def _checkResponse(self, response):
elif self.status_code == 422:
self._closeRequestSession()
raise BrainError('Requests Http Status Error: {0}\nValidation Errors:\n{1}'.format(http, json_data))
else:
elif self.status_code == 404:
self._closeRequestSession()
raise BrainError('Requests Http Status 404 Error: {0}\n{1}'.format(http, json_data))
else:
self._closeRequestSession()
# failsafe check if json_data is not a dict
if not isinstance(json_data, dict):
raise BrainError('Requests Http Status Error: {0}\n{1}'.format(http, json_data))

if str('api_error') in json_data:
apijson = json_data['api_error']
errmsg = '{0}'.format(apijson['message']) if 'message' in apijson else '{0}'.format(apijson['traceback'])
Expand Down

0 comments on commit 9e32476

Please sign in to comment.