Skip to content

Commit aa405c7

Browse files
committed
api: Fail fast on UNAUTHORIZED/BAD_REQUEST in call_on_each_event. (Fixes #783)
1 parent 0a9b91f commit aa405c7

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

zulip/zulip/__init__.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -763,6 +763,13 @@ def do_register() -> Tuple[str, int]:
763763
# TODO: Make this use our backoff library
764764
time.sleep(1)
765765
continue
766+
# Fail fast on clearly misconfigured clients to avoid silent retries.
767+
if res.get("result") == "error":
768+
code = res.get("code")
769+
if code in ("UNAUTHORIZED", "BAD_REQUEST"):
770+
# UNAUTHORIZED -> bad/expired credentials
771+
# BAD_REQUEST -> invalid parameters (often bad narrow)
772+
raise ZulipError(f"{code}: {res.get('msg', '')}")
766773

767774
if "error" in res["result"]:
768775
if res["result"] == "http-error":

0 commit comments

Comments
 (0)