zulip: Reraise exceptions in do_api_query.
There are cases where the call to an endpoint may result in an exception the traceback for which is converted into JSON and returned to the caller. In the case of such an unsuccessful response, we should just reraise the exception instead of parsing the response as though it was successful.
This commit is contained in:
parent
05d591a906
commit
7c3967f777
|
@ -681,10 +681,7 @@ class Client:
|
||||||
continue
|
continue
|
||||||
else:
|
else:
|
||||||
end_error_retry(False)
|
end_error_retry(False)
|
||||||
return {
|
raise
|
||||||
"msg": f"Connection error:\n{traceback.format_exc()}",
|
|
||||||
"result": "connection-error",
|
|
||||||
}
|
|
||||||
except requests.exceptions.ConnectionError:
|
except requests.exceptions.ConnectionError:
|
||||||
if not self.has_connected:
|
if not self.has_connected:
|
||||||
# If we have never successfully connected to the server, don't
|
# If we have never successfully connected to the server, don't
|
||||||
|
@ -696,16 +693,10 @@ class Client:
|
||||||
if error_retry(""):
|
if error_retry(""):
|
||||||
continue
|
continue
|
||||||
end_error_retry(False)
|
end_error_retry(False)
|
||||||
return {
|
raise
|
||||||
"msg": f"Connection error:\n{traceback.format_exc()}",
|
|
||||||
"result": "connection-error",
|
|
||||||
}
|
|
||||||
except Exception:
|
except Exception:
|
||||||
# We'll split this out into more cases as we encounter new bugs.
|
# We'll split this out into more cases as we encounter new bugs.
|
||||||
return {
|
raise
|
||||||
"msg": f"Unexpected error:\n{traceback.format_exc()}",
|
|
||||||
"result": "unexpected-error",
|
|
||||||
}
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
if requests_json_is_function:
|
if requests_json_is_function:
|
||||||
|
@ -782,16 +773,28 @@ class Client:
|
||||||
if queue_id is None:
|
if queue_id is None:
|
||||||
(queue_id, last_event_id) = do_register()
|
(queue_id, last_event_id) = do_register()
|
||||||
|
|
||||||
|
try:
|
||||||
res = self.get_events(queue_id=queue_id, last_event_id=last_event_id)
|
res = self.get_events(queue_id=queue_id, last_event_id=last_event_id)
|
||||||
|
except (
|
||||||
|
requests.exceptions.Timeout,
|
||||||
|
requests.exceptions.SSLError,
|
||||||
|
requests.exceptions.ConnectionError,
|
||||||
|
):
|
||||||
|
if self.verbose:
|
||||||
|
print(f"Connection error fetching events:\n{traceback.format_exc()}")
|
||||||
|
# TODO: Make this use our backoff library
|
||||||
|
time.sleep(1)
|
||||||
|
continue
|
||||||
|
except Exception:
|
||||||
|
print(f"Unexpected error:\n{traceback.format_exc()}")
|
||||||
|
# TODO: Make this use our backoff library
|
||||||
|
time.sleep(1)
|
||||||
|
continue
|
||||||
|
|
||||||
if "error" in res["result"]:
|
if "error" in res["result"]:
|
||||||
if res["result"] == "http-error":
|
if res["result"] == "http-error":
|
||||||
if self.verbose:
|
if self.verbose:
|
||||||
print("HTTP error fetching events -- probably a server restart")
|
print("HTTP error fetching events -- probably a server restart")
|
||||||
elif res["result"] == "connection-error":
|
|
||||||
if self.verbose:
|
|
||||||
print(
|
|
||||||
"Connection error fetching events -- probably server is temporarily down?"
|
|
||||||
)
|
|
||||||
else:
|
else:
|
||||||
if self.verbose:
|
if self.verbose:
|
||||||
print("Server returned error:\n{}".format(res["msg"]))
|
print("Server returned error:\n{}".format(res["msg"]))
|
||||||
|
|
Loading…
Reference in a new issue