8
8
class ErrorCode (IntegerChoices ):
9
9
"""常用错误码"""
10
10
11
- SUCCESS = (0 , "成功" )
12
- FAIL = (1 , "失败" )
13
- PARAMS_ERROR = (2 , "参数错误" )
14
- RETRY = (10 , "重试" )
15
- RETRY_LATER = (11 , "稍后重试" )
11
+ SUCCESS = (0 , "Success" ) # 成功
12
+ FAIL = (1 , "Fail" ) # 失败
13
+ PARAMS_ERROR = (2 , "Parameter error" ) # 参数错误
14
+ RETRY = (10 , "Retry" ) # 重试
15
+ RETRY_LATER = (11 , "Try again later" ) # 稍后重试
16
16
# 用户相关错误
17
- USER_NOT_FOUND = (40100 , "用户不存在" )
18
- USER_PASSWORD_ERROR = (40101 , "用户名或者密码错误" )
19
- USER_IS_EXIST = (40102 , "用户已存在" )
20
- USER_NAME_IS_EXIST = (40103 , "用户名已存在" )
21
- USER_MOBILE_IS_EXIST = (40104 , "用户手机号已存在" )
22
- USER_EMAIL_IS_EXIST = (40105 , "用户邮箱已存在" )
17
+ USER_NOT_FOUND = (40100 , "User does not exist" ) # 用户不存在
18
+ USER_PASSWORD_ERROR = (40101 , "Username or password is incorrect" ) # 用户名或者密码错误
19
+ USER_IS_EXIST = (40102 , "User already exists" ) # 用户已存在
20
+ USER_NAME_IS_EXIST = (40103 , "Username already exists" ) # 用户名已存在
21
+ USER_MOBILE_IS_EXIST = (40104 , "User mobile phone number already exists" ) # 用户手机号已存在
22
+ USER_EMAIL_IS_EXIST = (40105 , "User mailbox already exists" ) # 用户邮箱已存在
23
23
24
24
# 用户权限相关
25
- USER_IS_NOT_LOGIN = (40200 , "用户未登录" )
26
- USER_IS_NOT_ACTIVE = (40201 , "用户未激活" )
27
- USER_PERMISSION_DENIED = (40203 , "用户权限不足" )
28
- USER_IS_NOT_ADMIN = (40204 , "用户不是管理员" )
25
+ USER_IS_NOT_LOGIN = (40200 , "User is not logged in" ) # 用户未登录
26
+ USER_IS_NOT_ACTIVE = (40201 , "User is not activated" ) # 用户未激活
27
+ USER_PERMISSION_DENIED = (40203 , "Insufficient user rights" ) # 用户权限不足
28
+ USER_IS_NOT_ADMIN = (40204 , "User is not an administrator" ) # 用户不是管理员
29
29
# 系统错误
30
- SYSTEM_ERROR = (50000 , "系统错误" )
31
- SYSTEM_BUSY = (50001 , "系统繁忙" )
30
+ SYSTEM_ERROR = (50000 , "System error" ) # 系统错误
31
+ SYSTEM_BUSY = (50001 , "The system is busy" ) # 系统繁忙
32
32
33
33
34
34
class ApiException (HTTPException ):
35
35
def __init__ (
36
- self ,
37
- detail : Any ,
38
- status_code : int = 200 ,
39
- content : Any = None ,
40
- headers : Optional [Dict [str , Any ]] = None ,
36
+ self ,
37
+ detail : Any ,
38
+ status_code : int = 200 ,
39
+ content : Any = None ,
40
+ headers : Optional [Dict [str , Any ]] = None ,
41
41
) -> None :
42
42
self .content = content
43
43
super ().__init__ (status_code = status_code , detail = detail , headers = headers )
@@ -47,11 +47,11 @@ class ApiError(ApiException):
47
47
"""API异常基类"""
48
48
49
49
def __init__ (
50
- self ,
51
- status : int = ErrorCode .FAIL ,
52
- msg : str = "" ,
53
- headers : Optional [Dict [str , Any ]] = None ,
54
- ** extra ,
50
+ self ,
51
+ status : int = ErrorCode .FAIL ,
52
+ msg : str = "" ,
53
+ headers : Optional [Dict [str , Any ]] = None ,
54
+ ** extra ,
55
55
):
56
56
self .status = status
57
57
self .extra = extra
0 commit comments