Skip to content

Commit 66cd603

Browse files
authored
Merge pull request #24 from lovmat/check-content-type-before-assuming-json-on-api-call-error
Checking Content-Type in response before assuming json when api call …
2 parents 1eaf463 + e6d4e8b commit 66cd603

1 file changed

Lines changed: 4 additions & 1 deletion

File tree

typesense/api_call.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,10 @@ def make_request(self, fn, endpoint, as_json, **kwargs):
108108

109109
# We should raise a custom exception if status code is not 20X
110110
if not 200 <= r.status_code < 300:
111-
error_message = r.json().get('message', 'API error.')
111+
if r.headers.get('Content-Type', '').startswith('application/json'):
112+
error_message = r.json().get('message', 'API error.')
113+
else:
114+
error_message = 'API error.'
112115
# Raised exception will be caught and retried
113116
raise ApiCall.get_exception(r.status_code)(r.status_code, error_message)
114117

0 commit comments

Comments
 (0)