Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #55 add check around content prior to JSON parse #56

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 11 additions & 8 deletions src/jsonapi_client/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -535,14 +535,17 @@ def http_request(self, http_method: str, url: str, send_json: dict,
headers=headers,
**kwargs)

response_json = response.json()
if response.status_code not in expected_statuses:
raise DocumentError(f'Could not {http_method.upper()} '
f'({response.status_code}): '
f'{error_from_response(response_json)}',
errors={'status_code': response.status_code},
response=response,
json_data=send_json)
if (response.status_code == HttpStatus.NO_CONTENT_204):
response_json = {}
else:
response_json = response.json()
if response.status_code not in expected_statuses:
raise DocumentError(f'Could not {http_method.upper()} '
f'({response.status_code}): '
f'{error_from_response(response_json)}',
errors={'status_code': response.status_code},
response=response,
json_data=send_json)

return response.status_code, response_json \
if response.content \
Expand Down