From 903ad0ecf6ea03064ba7acbd01fd33b42dc464b7 Mon Sep 17 00:00:00 2001 From: wxg0103 <727495428@qq.com> Date: Tue, 23 Dec 2025 18:29:42 +0800 Subject: [PATCH] chore: add SEND_EMAIL_ERROR exception code for email-related validations --- apps/common/constants/exception_code_constants.py | 1 + apps/users/serializers/user.py | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/apps/common/constants/exception_code_constants.py b/apps/common/constants/exception_code_constants.py index 8d1cefc46..77faa46a1 100644 --- a/apps/common/constants/exception_code_constants.py +++ b/apps/common/constants/exception_code_constants.py @@ -42,3 +42,4 @@ class ExceptionCodeConstants(Enum): PASSWORD_NOT_EQ_RE_PASSWORD = ExceptionCodeConstantsValue(1007, _('Password and confirmation password are inconsistent')) NICKNAME_IS_EXIST = ExceptionCodeConstantsValue(1008, _('The nickname is already registered')) + SEND_EMAIL_ERROR = ExceptionCodeConstantsValue(1009, _("Email sending failed")) diff --git a/apps/users/serializers/user.py b/apps/users/serializers/user.py index b24202f78..e607dede9 100644 --- a/apps/users/serializers/user.py +++ b/apps/users/serializers/user.py @@ -1047,9 +1047,9 @@ class SendEmailSerializer(serializers.Serializer): super().is_valid(raise_exception=raise_exception) user_exists = QuerySet(User).filter(email=self.data.get('email')).exists() if not user_exists and self.data.get('type') == 'reset_password': - raise ExceptionCodeConstants.EMAIL_IS_NOT_EXIST.value.to_app_api_exception() + raise ExceptionCodeConstants.SEND_EMAIL_ERROR.value.to_app_api_exception() elif user_exists and self.data.get('type') == 'register': - raise ExceptionCodeConstants.EMAIL_IS_EXIST.value.to_app_api_exception() + raise ExceptionCodeConstants.SEND_EMAIL_ERROR.value.to_app_api_exception() code_cache_key = self.data.get('email') + ":" + self.data.get("type") code_cache_key_lock = code_cache_key + "_lock" ttl = cache.ttl(code_cache_key_lock, version=version)