chore: add SEND_EMAIL_ERROR exception code for email-related validations

This commit is contained in:
wxg0103 2025-12-23 18:29:42 +08:00
parent 6d5664c674
commit 903ad0ecf6
2 changed files with 3 additions and 2 deletions

View File

@ -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"))

View File

@ -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)