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.

register_push_device: Add an error code to push-not-configured error.

Prakhar Pratyush1c7dd83dbe83
diff --git a/zerver/lib/exceptions.py b/zerver/lib/exceptions.py
index 45da9d6ce87..8fd31383d27 100644
--- a/zerver/lib/exceptions.py
+++ b/zerver/lib/exceptions.py
@@ -61,6 +61,7 @@ class ErrorCode(Enum):
HOSTNAME_ALREADY_IN_USE_BOUNCER_ERROR = auto()
INVALID_BOUNCER_PUBLIC_KEY = auto()
REQUEST_EXPIRED = auto()
+ PUSH_SERVICE_NOT_CONFIGURED = auto()
class JsonableError(Exception):
@@ -863,3 +864,15 @@ class InvalidEncryptedPushRegistrationError(JsonableError):
@override
def msg_format() -> str:
return _("Invalid encrypted_push_registration")
+
+
+class PushServiceNotConfiguredError(JsonableError):
+ code = ErrorCode.PUSH_SERVICE_NOT_CONFIGURED
+
+ def __init__(self) -> None:
+ pass
+
+ @staticmethod
+ @override
+ def msg_format() -> str:
+ return _("Server is not configured to use push notification service.")
diff --git a/zerver/openapi/zulip.yaml b/zerver/openapi/zulip.yaml
index e7337061bbe..3433681638c 100644
--- a/zerver/openapi/zulip.yaml
+++ b/zerver/openapi/zulip.yaml
@@ -12619,7 +12619,7 @@ paths:
{
"result": "error",
"msg": "Server is not configured to use push notification service.",
- "code": "BAD_REQUEST",
+ "code": "PUSH_SERVICE_NOT_CONFIGURED",
}
description: |
Error when the server is not configured to use push notification service:
diff --git a/zerver/views/push_notifications.py b/zerver/views/push_notifications.py
index a26c3a589e0..48082e0c394 100644
--- a/zerver/views/push_notifications.py
+++ b/zerver/views/push_notifications.py
@@ -15,6 +15,7 @@ from zerver.lib.exceptions import (
JsonableError,
MissingRemoteRealmError,
OrganizationOwnerRequiredError,
+ PushServiceNotConfiguredError,
RemoteRealmServerMismatchError,
ResourceNotFoundError,
)
@@ -280,7 +281,7 @@ def register_push_device(
encrypted_push_registration: str,
) -> HttpResponse:
if not (settings.ZILENCER_ENABLED or uses_notification_bouncer()):
- raise JsonableError(_("Server is not configured to use push notification service."))
+ raise PushServiceNotConfiguredError
# Idempotency
already_registered = PushDevice.objects.filter(