Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

error.py 5.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. from libs.exception import BaseHTTPException
  2. class ApiKeyAuthFailedError(BaseHTTPException):
  3. error_code = "auth_failed"
  4. description = "{message}"
  5. code = 500
  6. class InvalidEmailError(BaseHTTPException):
  7. error_code = "invalid_email"
  8. description = "The email address is not valid."
  9. code = 400
  10. class PasswordMismatchError(BaseHTTPException):
  11. error_code = "password_mismatch"
  12. description = "The passwords do not match."
  13. code = 400
  14. class InvalidTokenError(BaseHTTPException):
  15. error_code = "invalid_or_expired_token"
  16. description = "The token is invalid or has expired."
  17. code = 400
  18. class PasswordResetRateLimitExceededError(BaseHTTPException):
  19. error_code = "password_reset_rate_limit_exceeded"
  20. description = "Too many password reset emails have been sent. Please try again in {minutes} minutes."
  21. code = 429
  22. def __init__(self, minutes: int = 1):
  23. description = self.description.format(minutes=int(minutes)) if self.description else None
  24. super().__init__(description=description)
  25. class EmailRegisterRateLimitExceededError(BaseHTTPException):
  26. error_code = "email_register_rate_limit_exceeded"
  27. description = "Too many email register emails have been sent. Please try again in {minutes} minutes."
  28. code = 429
  29. def __init__(self, minutes: int = 1):
  30. description = self.description.format(minutes=int(minutes)) if self.description else None
  31. super().__init__(description=description)
  32. class EmailChangeRateLimitExceededError(BaseHTTPException):
  33. error_code = "email_change_rate_limit_exceeded"
  34. description = "Too many email change emails have been sent. Please try again in {minutes} minutes."
  35. code = 429
  36. def __init__(self, minutes: int = 1):
  37. description = self.description.format(minutes=int(minutes)) if self.description else None
  38. super().__init__(description=description)
  39. class OwnerTransferRateLimitExceededError(BaseHTTPException):
  40. error_code = "owner_transfer_rate_limit_exceeded"
  41. description = "Too many owner transfer emails have been sent. Please try again in {minutes} minutes."
  42. code = 429
  43. def __init__(self, minutes: int = 1):
  44. description = self.description.format(minutes=int(minutes)) if self.description else None
  45. super().__init__(description=description)
  46. class EmailCodeError(BaseHTTPException):
  47. error_code = "email_code_error"
  48. description = "Email code is invalid or expired."
  49. code = 400
  50. class EmailOrPasswordMismatchError(BaseHTTPException):
  51. error_code = "email_or_password_mismatch"
  52. description = "The email or password is mismatched."
  53. code = 400
  54. class AuthenticationFailedError(BaseHTTPException):
  55. error_code = "authentication_failed"
  56. description = "Invalid email or password."
  57. code = 401
  58. class EmailPasswordLoginLimitError(BaseHTTPException):
  59. error_code = "email_code_login_limit"
  60. description = "Too many incorrect password attempts. Please try again later."
  61. code = 429
  62. class EmailCodeLoginRateLimitExceededError(BaseHTTPException):
  63. error_code = "email_code_login_rate_limit_exceeded"
  64. description = "Too many login emails have been sent. Please try again in {minutes} minutes."
  65. code = 429
  66. def __init__(self, minutes: int = 5):
  67. description = self.description.format(minutes=int(minutes)) if self.description else None
  68. super().__init__(description=description)
  69. class EmailCodeAccountDeletionRateLimitExceededError(BaseHTTPException):
  70. error_code = "email_code_account_deletion_rate_limit_exceeded"
  71. description = "Too many account deletion emails have been sent. Please try again in {minutes} minutes."
  72. code = 429
  73. def __init__(self, minutes: int = 5):
  74. description = self.description.format(minutes=int(minutes)) if self.description else None
  75. super().__init__(description=description)
  76. class EmailPasswordResetLimitError(BaseHTTPException):
  77. error_code = "email_password_reset_limit"
  78. description = "Too many failed password reset attempts. Please try again in 24 hours."
  79. code = 429
  80. class EmailRegisterLimitError(BaseHTTPException):
  81. error_code = "email_register_limit"
  82. description = "Too many failed email register attempts. Please try again in 24 hours."
  83. code = 429
  84. class EmailChangeLimitError(BaseHTTPException):
  85. error_code = "email_change_limit"
  86. description = "Too many failed email change attempts. Please try again in 24 hours."
  87. code = 429
  88. class EmailAlreadyInUseError(BaseHTTPException):
  89. error_code = "email_already_in_use"
  90. description = "A user with this email already exists."
  91. code = 400
  92. class OwnerTransferLimitError(BaseHTTPException):
  93. error_code = "owner_transfer_limit"
  94. description = "Too many failed owner transfer attempts. Please try again in 24 hours."
  95. code = 429
  96. class NotOwnerError(BaseHTTPException):
  97. error_code = "not_owner"
  98. description = "You are not the owner of the workspace."
  99. code = 400
  100. class CannotTransferOwnerToSelfError(BaseHTTPException):
  101. error_code = "cannot_transfer_owner_to_self"
  102. description = "You cannot transfer ownership to yourself."
  103. code = 400
  104. class MemberNotInTenantError(BaseHTTPException):
  105. error_code = "member_not_in_tenant"
  106. description = "The member is not in the workspace."
  107. code = 400