Skip to content

Commit

Permalink
Merge pull request #1 from tim-hitchins-ekkosense/issue/qvantel#55-de…
Browse files Browse the repository at this point in the history
…lete-204-parse-error

Fix qvantel#55 add check around content prior to JSON parse
  • Loading branch information
tim-hitchins-ekkosense authored Feb 16, 2022
2 parents 9df28f5 + a3fdf74 commit a904bd9
Showing 1 changed file with 11 additions and 8 deletions.
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

0 comments on commit a904bd9

Please sign in to comment.