Skip to content

armgit / zulip

Public Imported from GitHub
0

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.py
index 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 happen
result_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 admins
raise 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 PushNotificationsDisallowedByBouncerError
raise 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 InvalidRemotePushDeviceTokenError
raise 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 MissingRemoteRealmError
elif (
- 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.