Skip to content

Commit

Permalink
Merge pull request #27 from sbarbett/shane-dev
Browse files Browse the repository at this point in the history
changes to x-task-id parsing logic for responses without a json body
  • Loading branch information
stevedejong authored Dec 3, 2024
2 parents b511036 + 9a7420b commit c3d6a16
Showing 1 changed file with 7 additions and 9 deletions.
16 changes: 7 additions & 9 deletions ultra_rest_client/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit c3d6a16

Please sign in to comment.