-
-
Notifications
You must be signed in to change notification settings - Fork 534
/
exception.py
146 lines (93 loc) · 2.76 KB
/
exception.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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
异常
====
下列文档中的异常是所有 NoneBot 运行时可能会抛出的。
这些异常并非所有需要用户处理,在 NoneBot 内部运行时被捕获,并进行对应操作。
"""
from nonebot.typing import List, Type, Optional
class _ExceptionContainer(Exception):
def __init__(self, exceptions: List[Type[Exception]]) -> None:
self.exceptions = exceptions
class IgnoredException(Exception):
"""
:说明:
指示 NoneBot 应该忽略该事件。可由 PreProcessor 抛出。
:参数:
* ``reason``: 忽略事件的原因
"""
def __init__(self, reason):
self.reason = reason
def __repr__(self):
return f"<IgnoredException, reason={self.reason}>"
def __str__(self):
return self.__repr__()
class PausedException(Exception):
"""
:说明:
指示 NoneBot 结束当前 ``Handler`` 并等待下一条消息后继续下一个 ``Handler``。
可用于用户输入新信息。
:用法:
可以在 ``Handler`` 中通过 ``Matcher.pause()`` 抛出。
"""
pass
class RejectedException(Exception):
"""
:说明:
指示 NoneBot 结束当前 ``Handler`` 并等待下一条消息后重新运行当前 ``Handler``。
可用于用户重新输入。
:用法:
可以在 ``Handler`` 中通过 ``Matcher.reject()`` 抛出。
"""
pass
class FinishedException(Exception):
"""
:说明:
指示 NoneBot 结束当前 ``Handler`` 且后续 ``Handler`` 不再被运行。
可用于结束用户会话。
:用法:
可以在 ``Handler`` 中通过 ``Matcher.finish()`` 抛出。
"""
pass
class ExpiredException(Exception):
"""
:说明:
指示 NoneBot 当前 ``Matcher`` 已失效。
:用法:
当 ``Matcher`` 运行前检查时抛出。
"""
pass
class StopPropagation(Exception):
"""
:说明:
指示 NoneBot 终止事件向下层传播。
:用法:
在 ``Matcher.block == True`` 时抛出。
"""
pass
class ApiNotAvailable(Exception):
"""
:说明:
在 API 连接不可用时抛出。
"""
pass
class NetworkError(Exception):
"""
:说明:
在网络出现问题时抛出,如: API 请求地址不正确, API 请求无返回或返回状态非正常等。
"""
pass
class ActionFailed(Exception):
"""
:说明:
API 请求成功返回数据,但 API 操作失败。
:参数:
* ``retcode``: 错误代码
"""
def __init__(self, retcode: Optional[int]):
self.retcode = retcode
def __repr__(self):
return f"<ActionFailed, retcode={self.retcode}>"
def __str__(self):
return self.__repr__()