Skip to content

Commit b07a82d

Browse files
add safe handling of invalid json responses (#108)
* add safe handling of invalid json responses * add response.text to error message body
1 parent 85dfdf1 commit b07a82d

1 file changed

Lines changed: 9 additions & 1 deletion

File tree

plaid/requester.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,15 @@ def _requests_http_request(url, method, data, timeout=DEFAULT_TIMEOUT):
3030

3131
def http_request(url, method=None, data=None, timeout=DEFAULT_TIMEOUT):
3232
response = _requests_http_request(url, method, data or {}, timeout)
33-
response_body = json.loads(response.text)
33+
try:
34+
response_body = json.loads(response.text)
35+
except json.JSONDecodeError:
36+
raise PlaidError.from_response({
37+
'error_message': response.text,
38+
'error_type': 'API_ERROR',
39+
'error_code': 'INTERNAL_SERVER_ERROR',
40+
'display_message': None,
41+
})
3442
if response_body.get('error_type'):
3543
raise PlaidError.from_response(response_body)
3644
else:

0 commit comments

Comments
 (0)