Skip to content

Commit 903ad0e

Browse files
committed
chore: add SEND_EMAIL_ERROR exception code for email-related validations
1 parent 6d5664c commit 903ad0e

File tree

2 files changed

+3
-2
lines changed

2 files changed

+3
-2
lines changed

apps/common/constants/exception_code_constants.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,3 +42,4 @@ class ExceptionCodeConstants(Enum):
4242
PASSWORD_NOT_EQ_RE_PASSWORD = ExceptionCodeConstantsValue(1007,
4343
_('Password and confirmation password are inconsistent'))
4444
NICKNAME_IS_EXIST = ExceptionCodeConstantsValue(1008, _('The nickname is already registered'))
45+
SEND_EMAIL_ERROR = ExceptionCodeConstantsValue(1009, _("Email sending failed"))

apps/users/serializers/user.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1047,9 +1047,9 @@ def is_valid(self, *, raise_exception=False):
10471047
super().is_valid(raise_exception=raise_exception)
10481048
user_exists = QuerySet(User).filter(email=self.data.get('email')).exists()
10491049
if not user_exists and self.data.get('type') == 'reset_password':
1050-
raise ExceptionCodeConstants.EMAIL_IS_NOT_EXIST.value.to_app_api_exception()
1050+
raise ExceptionCodeConstants.SEND_EMAIL_ERROR.value.to_app_api_exception()
10511051
elif user_exists and self.data.get('type') == 'register':
1052-
raise ExceptionCodeConstants.EMAIL_IS_EXIST.value.to_app_api_exception()
1052+
raise ExceptionCodeConstants.SEND_EMAIL_ERROR.value.to_app_api_exception()
10531053
code_cache_key = self.data.get('email') + ":" + self.data.get("type")
10541054
code_cache_key_lock = code_cache_key + "_lock"
10551055
ttl = cache.ttl(code_cache_key_lock, version=version)

0 commit comments

Comments
 (0)