Skip to content

Commit

Permalink
add safe handling of invalid json responses (#108)
Browse files Browse the repository at this point in the history
* add safe handling of invalid json responses

* add response.text to error message body
  • Loading branch information
michaelckelly authored Dec 5, 2017
1 parent 85dfdf1 commit b07a82d
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion plaid/requester.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,15 @@ def _requests_http_request(url, method, data, timeout=DEFAULT_TIMEOUT):

def http_request(url, method=None, data=None, timeout=DEFAULT_TIMEOUT):
response = _requests_http_request(url, method, data or {}, timeout)
response_body = json.loads(response.text)
try:
response_body = json.loads(response.text)
except json.JSONDecodeError:
raise PlaidError.from_response({
'error_message': response.text,
'error_type': 'API_ERROR',
'error_code': 'INTERNAL_SERVER_ERROR',
'display_message': None,
})
if response_body.get('error_type'):
raise PlaidError.from_response(response_body)
else:
Expand Down

0 comments on commit b07a82d

Please sign in to comment.