api: Fix error reporting when result is not JSON.
Previously, we would return a JSONDecodeError to the user in the event that the server returned a 500 error (or other non-JSON content). (imported from commit 1624dfec6ac65d34216f4de91e33116a54e414fa)
This commit is contained in:
parent
b71742b021
commit
2fd94c5e63
|
@ -187,15 +187,19 @@ class Client(object):
|
|||
return {'msg': "Unexpected error:\n%s" % traceback.format_exc(),
|
||||
"result": "unexpected-error"}
|
||||
|
||||
if requests_json_is_function:
|
||||
json_result = res.json()
|
||||
else:
|
||||
json_result = res.json
|
||||
try:
|
||||
if requests_json_is_function:
|
||||
json_result = res.json()
|
||||
else:
|
||||
json_result = res.json
|
||||
except Exception:
|
||||
json_result = None
|
||||
|
||||
if json_result is not None:
|
||||
end_error_retry(True)
|
||||
return json_result
|
||||
end_error_retry(False)
|
||||
return {'msg': res.text, "result": "http-error",
|
||||
return {'msg': "Unexpected error from the server", "result": "http-error",
|
||||
"status_code": res.status_code}
|
||||
|
||||
@classmethod
|
||||
|
|
Loading…
Reference in a new issue