From a3fdf74ae1589c1f156220dd336acc849dd1c926 Mon Sep 17 00:00:00 2001 From: Tim Hitchins Date: Wed, 16 Feb 2022 21:42:36 +0000 Subject: [PATCH] Fix #55 add check around content prior to JSON parse --- src/jsonapi_client/session.py | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/src/jsonapi_client/session.py b/src/jsonapi_client/session.py index 4ce00d2..e8ab908 100644 --- a/src/jsonapi_client/session.py +++ b/src/jsonapi_client/session.py @@ -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 \