Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
errors: Use shared class for message when email is already in use.
ImDooMLorDb6f09b6dab0e
diff --git a/zerver/lib/exceptions.py b/zerver/lib/exceptions.pyindex 092ee93ec95..fb38606f1eb 100644--- a/zerver/lib/exceptions.py+++ b/zerver/lib/exceptions.py@@ -756,3 +756,13 @@ class CannotManageDefaultChannelError(JsonableError):@overridedef msg_format() -> str:return _("You do not have permission to change default channels.")+++class EmailAlreadyInUseError(JsonableError):+ def __init__(self) -> None:+ pass++ @staticmethod+ @override+ def msg_format() -> str:+ return _("Email is already in use.")diff --git a/zerver/openapi/zulip.yaml b/zerver/openapi/zulip.yamlindex b93fa621868..1993d389892 100644--- a/zerver/openapi/zulip.yaml+++ b/zerver/openapi/zulip.yaml@@ -9433,7 +9433,7 @@ paths:- example:{"code": "BAD_REQUEST",- "msg": "Email '[email protected]' already in use",+ "msg": "Email is already in use.","result": "error",}description: |diff --git a/zerver/tests/test_bots.py b/zerver/tests/test_bots.pyindex 8b82fd838a8..941195bf346 100644--- a/zerver/tests/test_bots.py+++ b/zerver/tests/test_bots.py@@ -251,7 +251,7 @@ class BotTest(ZulipTestCase, UploadSerializeMixin):short_name="hambot",)result = self.client_post("/json/bots", bot_info)- self.assert_json_error(result, "Email '[email protected]' already in use")+ self.assert_json_error(result, "Email is already in use.")dup_full_name = "The Bot of Hamlet"diff --git a/zerver/tests/test_example.py b/zerver/tests/test_example.pyindex a097d6e9e2a..c6b6e098fee 100644--- a/zerver/tests/test_example.py+++ b/zerver/tests/test_example.py@@ -214,7 +214,7 @@ class TestFullStack(ZulipTestCase):# Verify error handling when the user already exists.result = self.client_post("/json/users", valid_params)- self.assert_json_error(result, "Email '[email protected]' already in use", 400)+ self.assert_json_error(result, "Email is already in use.", 400)def test_tornado_redirects(self) -> None:# Let's poke a bit at Zulip's event system.diff --git a/zerver/tests/test_users.py b/zerver/tests/test_users.pyindex d5e08336cdc..c4f99e1c71d 100644--- a/zerver/tests/test_users.py+++ b/zerver/tests/test_users.py@@ -1336,7 +1336,7 @@ class AdminCreateUserTest(ZulipTestCase):# we can't create the same user twice.result = self.client_post("/json/users", valid_params)- self.assert_json_error(result, "Email '[email protected]' already in use")+ self.assert_json_error(result, "Email is already in use.")# Don't allow user to sign up with disposable email.realm.emails_restricted_to_domains = Falsediff --git a/zerver/views/users.py b/zerver/views/users.pyindex 75273f9ac39..b17559976eb 100644--- a/zerver/views/users.py+++ b/zerver/views/users.py@@ -45,6 +45,7 @@ from zerver.lib.bot_config import set_bot_configfrom zerver.lib.email_validation import email_allowed_for_realm, validate_email_not_already_in_realmfrom zerver.lib.exceptions import (CannotDeactivateLastUserError,+ EmailAlreadyInUseError,JsonableError,MissingAuthenticationError,OrganizationAdministratorRequiredError,@@ -603,7 +604,7 @@ def add_bot_backend(raise JsonableError(_("Bad name or username"))try:get_user_by_delivery_email(email, user_profile.realm)- raise JsonableError(_("Email '{email}' already in use").format(email=email))+ raise EmailAlreadyInUseErrorexcept UserProfile.DoesNotExist:pass@@ -810,7 +811,7 @@ def create_user_backend(try:get_user_by_delivery_email(email, user_profile.realm)- raise JsonableError(_("Email '{email}' already in use").format(email=email))+ raise EmailAlreadyInUseErrorexcept UserProfile.DoesNotExist:pass