-
Notifications
You must be signed in to change notification settings - Fork 677
/
Copy pathexceptions.py
77 lines (48 loc) · 2.71 KB
/
exceptions.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
from typing import Any
class SelfDefinedException(Exception):
def __init__(self, reason: Any = None, message: str = "", code: int = -1) -> None:
self.reason = reason # 异常主要原因
self.message = message # 更细节的描述
self.code = code # 错误码:-1 为默认;0~1000 以内正数为 http 错误码;10000 以上为自定义错误码
def __str__(self):
return f"{self.__class__.__name__}: [{self.code}] {self.reason} {self.message}"
class AuthenticationFailedException(SelfDefinedException):
def __init__(self, message: str = ""):
super().__init__(reason="errors.authenticationFailed", message=message, code=10401)
class AuthorityDenyException(SelfDefinedException):
def __init__(self, message: str = ""):
super().__init__(reason="errors.authorityDeny", message=message, code=10403)
class UserNotExistException(SelfDefinedException):
def __init__(self, message: str = ""):
super().__init__(reason="errors.userNotExist", message=message)
class UserAlreadyExists(SelfDefinedException):
def __init__(self, message: str = ""):
super().__init__(reason="errors.userAlreadyExists", message=message)
class InvalidParamsException(SelfDefinedException):
def __init__(self, message: str = ""):
super().__init__(reason="errors.invalidParams", message=message)
class ResourceNotFoundException(SelfDefinedException):
def __init__(self, message: str = ""):
super().__init__(reason="errors.resourceNotFound", message=message, code=404)
class InvalidRequestException(SelfDefinedException):
def __init__(self, message: str = ""):
super().__init__(reason="errors.invalidRequest", message=message)
class InternalException(SelfDefinedException):
def __init__(self, message: str = ""):
super().__init__(reason="errors.internal", message=message)
class ConfigException(SelfDefinedException):
def __init__(self, message: str = ""):
super().__init__(reason="errors.config", message=message)
class OpenaiException(SelfDefinedException):
def __init__(self, reason: str, message: str = "", code: int = -1):
super().__init__(reason=reason, message=message, code=code)
class OpenaiWebException(OpenaiException):
def __init__(self, message: str = "", code: int = -1):
super().__init__(reason="errors.openaiWeb", message=message, code=code)
class OpenaiApiException(OpenaiException):
def __init__(self, message: str = "", code: int = -1):
super().__init__(reason="errors.openaiWeb", message=message, code=code)
class ArkoseForwardException(Exception):
def __init__(self, message: str = "", code: int = 404):
self.message = message
self.code = code