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:
Tim Abbott 2013-07-29 18:02:28 -04:00
parent b71742b021
commit 2fd94c5e63

View file

@ -187,15 +187,19 @@ class Client(object):
return {'msg': "Unexpected error:\n%s" % traceback.format_exc(), return {'msg': "Unexpected error:\n%s" % traceback.format_exc(),
"result": "unexpected-error"} "result": "unexpected-error"}
if requests_json_is_function: try:
json_result = res.json() if requests_json_is_function:
else: json_result = res.json()
json_result = res.json else:
json_result = res.json
except Exception:
json_result = None
if json_result is not None: if json_result is not None:
end_error_retry(True) end_error_retry(True)
return json_result return json_result
end_error_retry(False) 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} "status_code": res.status_code}
@classmethod @classmethod