Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
send_to_push_bouncer: Avoid repeated `code` lookup in error handling.
Prakhar Pratyushc846302417d3
diff --git a/zerver/lib/remote_server.py b/zerver/lib/remote_server.pyindex e2a224e7fa6..329da72b521 100644--- a/zerver/lib/remote_server.py+++ b/zerver/lib/remote_server.py@@ -190,38 +190,29 @@ def send_to_push_bouncer(# If JSON parsing errors, just let that exception happenresult_dict = orjson.loads(res.content)msg = result_dict["msg"]- if "code" in result_dict and result_dict["code"] == "INVALID_ZULIP_SERVER":+ code = result_dict["code"] if "code" in result_dict else None+ if code == "INVALID_ZULIP_SERVER":# Invalid Zulip server credentials should email this server's adminsraise PushNotificationBouncerError(_("Push notifications bouncer error: {error}").format(error=msg))- elif "code" in result_dict and result_dict["code"] == "PUSH_NOTIFICATIONS_DISALLOWED":+ elif code == "PUSH_NOTIFICATIONS_DISALLOWED":from zerver.lib.push_notifications import PushNotificationsDisallowedByBouncerErrorraise PushNotificationsDisallowedByBouncerError(reason=msg)- elif (- endpoint == "push/test_notification"- and "code" in result_dict- and result_dict["code"] == "INVALID_REMOTE_PUSH_DEVICE_TOKEN"- ):+ elif endpoint == "push/test_notification" and code == "INVALID_REMOTE_PUSH_DEVICE_TOKEN":# This error from the notification debugging endpoint should just be directly# communicated to the device.# TODO: Extend this to use a more general mechanism when we add more such error responses.from zerver.lib.push_notifications import InvalidRemotePushDeviceTokenErrorraise InvalidRemotePushDeviceTokenError- elif (- endpoint == "server/billing"- and "code" in result_dict- and result_dict["code"] == "MISSING_REMOTE_REALM"- ): # nocoverage+ elif endpoint == "server/billing" and code == "MISSING_REMOTE_REALM": # nocoverage# The callers requesting this endpoint want the exception to propagate# so they can catch it.raise MissingRemoteRealmErrorelif (- endpoint == "server/billing"- and "code" in result_dict- and result_dict["code"] == "REMOTE_REALM_SERVER_MISMATCH_ERROR"+ endpoint == "server/billing" and code == "REMOTE_REALM_SERVER_MISMATCH_ERROR"): # nocoverage# The callers requesting this endpoint want the exception to propagate# so they can catch it.