diff --git a/nonebot/exception.py b/nonebot/exception.py index b374f4c5..4df3ea49 100644 --- a/nonebot/exception.py +++ b/nonebot/exception.py @@ -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