exception_code_constants.py 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. # coding=utf-8
  2. """
  3. @project: qabot
  4. @Author:虎
  5. @file: exception_code_constants.py
  6. @date:2023/9/4 14:09
  7. @desc: 异常常量类
  8. """
  9. from enum import Enum
  10. from common.exception.app_exception import AppApiException
  11. from django.utils.translation import gettext_lazy as _
  12. class ExceptionCodeConstantsValue:
  13. def __init__(self, code, message):
  14. self.code = code
  15. self.message = message
  16. def get_message(self):
  17. return self.message
  18. def get_code(self):
  19. return self.code
  20. def to_app_api_exception(self):
  21. return AppApiException(code=self.code, message=self.message)
  22. class ExceptionCodeConstants(Enum):
  23. INCORRECT_USERNAME_AND_PASSWORD = ExceptionCodeConstantsValue(1000, _('The username or password is incorrect'))
  24. NOT_AUTHENTICATION = ExceptionCodeConstantsValue(1001, _('Please log in first and bring the user Token'))
  25. EMAIL_SEND_ERROR = ExceptionCodeConstantsValue(1002, _('Email sending failed'))
  26. EMAIL_FORMAT_ERROR = ExceptionCodeConstantsValue(1003, _('Email format error'))
  27. EMAIL_IS_EXIST = ExceptionCodeConstantsValue(1004, _('The email has been registered, please log in directly'))
  28. EMAIL_IS_NOT_EXIST = ExceptionCodeConstantsValue(1005, _('The email is not registered, please register first'))
  29. CODE_ERROR = ExceptionCodeConstantsValue(1005,
  30. _('The verification code is incorrect or the verification code has expired'))
  31. USERNAME_IS_EXIST = ExceptionCodeConstantsValue(1006, _('The username has been registered, please log in directly'))
  32. USERNAME_ERROR = ExceptionCodeConstantsValue(1006,
  33. _('The username cannot be empty and must be between 6 and 20 characters long.'))
  34. PASSWORD_NOT_EQ_RE_PASSWORD = ExceptionCodeConstantsValue(1007,
  35. _('Password and confirmation password are inconsistent'))
  36. NICKNAME_IS_EXIST = ExceptionCodeConstantsValue(1008, _('The nickname is already registered'))
  37. SEND_EMAIL_ERROR = ExceptionCodeConstantsValue(1009, _("Email sending failed"))