🚧 add exception

This commit is contained in:
yanyongyu 2020-12-03 13:22:12 +08:00
parent 3638da7f2d
commit 7116532081

View File

@ -6,10 +6,19 @@
这些异常并非所有需要用户处理 NoneBot 内部运行时被捕获并进行对应操作
"""
from nonebot.typing import List, Type, Optional
from nonebot.typing import Optional
class IgnoredException(Exception):
class NoneBotException(Exception):
"""
:说明:
所有 NoneBot 发生的异常基类
"""
pass
class IgnoredException(NoneBotException):
"""
:说明:
@ -30,7 +39,7 @@ class IgnoredException(Exception):
return self.__repr__()
class PausedException(Exception):
class PausedException(NoneBotException):
"""
:说明:
@ -44,7 +53,7 @@ class PausedException(Exception):
pass
class RejectedException(Exception):
class RejectedException(NoneBotException):
"""
:说明:
@ -58,7 +67,7 @@ class RejectedException(Exception):
pass
class FinishedException(Exception):
class FinishedException(NoneBotException):
"""
:说明:
@ -72,7 +81,7 @@ class FinishedException(Exception):
pass
class StopPropagation(Exception):
class StopPropagation(NoneBotException):
"""
:说明:
@ -85,7 +94,7 @@ class StopPropagation(Exception):
pass
class RequestDenied(Exception):
class RequestDenied(NoneBotException):
"""
:说明:
@ -108,7 +117,22 @@ class RequestDenied(Exception):
return self.__repr__()
class ApiNotAvailable(Exception):
class AdapterException(NoneBotException):
"""
:说明:
代表 ``Adapter`` 抛出的异常所有的 ``Adapter`` 都要在内部继承自这个 ``Exception``
:参数:
* ``adapter_name: str``: 标识 adapter
"""
def __init__(self, adapter_name: str) -> None:
self.adapter_name = adapter_name
class ApiNotAvailable(AdapterException):
"""
:说明:
@ -117,7 +141,7 @@ class ApiNotAvailable(Exception):
pass
class NetworkError(Exception):
class NetworkError(AdapterException):
"""
:说明:
@ -126,7 +150,7 @@ class NetworkError(Exception):
pass
class ActionFailed(Exception):
class ActionFailed(AdapterException):
"""
:说明:
@ -145,18 +169,3 @@ class ActionFailed(Exception):
def __str__(self):
return self.__repr__()
class AdapterException(Exception):
"""
:说明:
代表 Adapter 抛出的异常所有的 Adapter 都要在内部继承自这个 `Exception`
:参数:
* ``adapter_name: str``: 标识 adapter
"""
def __init__(self, adapter_name: str) -> None:
self.adapter_name = adapter_name