push_notifs: Gracefully handle exception when server cant push.

The problem was that earlier this was just an uncaught JsonableError,
leading to a full traceback getting spammed to the admins.
The prior commit introduced a clear .code for this error on the bouncer
side, meaning the self-hosted server can now detect that and handle it
nicely, by just logging.error about it and also take the opportunity to
adjust the realm.push_notifications_... flags.
This commit is contained in:
Mateusz Mandera
2024-02-07 00:38:35 +01:00
committed by Tim Abbott
parent 3bda31c48c
commit 5672595c2a
3 changed files with 97 additions and 1 deletions

View File

@@ -185,6 +185,10 @@ def send_to_push_bouncer(
raise PushNotificationBouncerError(
_("Push notifications bouncer error: {error}").format(error=msg)
)
elif "code" in result_dict and result_dict["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