From 9a7420b634896b53deb3c7376949399f97d7e884 Mon Sep 17 00:00:00 2001 From: sbarbett Date: Fri, 8 Nov 2024 09:36:12 -0500 Subject: [PATCH] changes to x-task-id parsing logic for responses without a json body --- ultra_rest_client/connection.py | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/ultra_rest_client/connection.py b/ultra_rest_client/connection.py index 93dafb4..22377e6 100644 --- a/ultra_rest_client/connection.py +++ b/ultra_rest_client/connection.py @@ -135,20 +135,18 @@ def _do_call(self, uri, method, params=None, body=None, retry=True, files=None, if response.headers.get('content-type') == 'application/zip': return response.content - json_body = {} try: json_body = response.json() - - # if this is a background task, add the task id (or location) to the body - if response.status_code == requests.codes.ACCEPTED: - if 'x-task-id' in response.headers: - json_body.update({"task_id": response.headers['x-task-id']}) - if 'location' in response.headers: - json_body.update({"location": response.headers['location']}) - except requests.exceptions.JSONDecodeError: json_body = {} + # if this is a background task, add the task id (or location) to the body + if response.status_code == requests.codes.ACCEPTED: + if 'x-task-id' in response.headers: + json_body.update({"task_id": response.headers['x-task-id']}) + if 'location' in response.headers: + json_body.update({"location": response.headers['location']}) + if isinstance(json_body, dict) and retry and json_body.get('errorCode') == 60001: self._refresh() return self._do_call(uri, method, params, body, False)