Skip to content

Commit 009fecb

Browse files
committed
[sc-104770] Adding error message when api returns non json
1 parent 9ec6f73 commit 009fecb

1 file changed

Lines changed: 11 additions & 1 deletion

File tree

python-lib/rest_api_client.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,17 @@ def request(self, method, url, can_raise_exeption=True, **kwargs):
157157
if response.status_code in [204]:
158158
self.pagination.update_next_page({}, response.links)
159159
return self.empty_json_response()
160-
json_response = response.json()
160+
try:
161+
json_response = response.json()
162+
except Exception as err:
163+
self.pagination.update_next_page({}, response.links)
164+
error_message = "Error '{}' when decoding JSON".format(str(err)[:100])
165+
logger.error(error_message)
166+
logger.error("response.content={}".format(response.content))
167+
if can_raise_exeption:
168+
raise RestAPIClientError("The API did not return JSON as expected. {}".format(error_message))
169+
return {"error": error_message}
170+
161171
self.pagination.update_next_page(json_response, response.links)
162172
return json_response
163173

0 commit comments

Comments
 (0)