2020-12-06 02:30:19 +08:00
|
|
|
from typing import Optional
|
|
|
|
|
2020-12-03 16:04:14 +08:00
|
|
|
from nonebot.exception import (AdapterException, ActionFailed as
|
|
|
|
BaseActionFailed, NetworkError as
|
|
|
|
BaseNetworkError, ApiNotAvailable as
|
|
|
|
BaseApiNotAvailable)
|
2020-12-03 15:07:03 +08:00
|
|
|
|
|
|
|
|
|
|
|
class CQHTTPAdapterException(AdapterException):
|
|
|
|
|
|
|
|
def __init__(self):
|
|
|
|
super().__init__("cqhttp")
|
|
|
|
|
|
|
|
|
2020-12-03 16:04:14 +08:00
|
|
|
class ActionFailed(BaseActionFailed, CQHTTPAdapterException):
|
2020-12-03 15:07:03 +08:00
|
|
|
"""
|
|
|
|
:说明:
|
|
|
|
|
|
|
|
API 请求返回错误信息。
|
|
|
|
|
|
|
|
:参数:
|
|
|
|
|
|
|
|
* ``retcode: Optional[int]``: 错误码
|
|
|
|
"""
|
|
|
|
|
2020-12-19 00:50:17 +08:00
|
|
|
def __init__(self, **kwargs):
|
2020-12-03 15:07:03 +08:00
|
|
|
super().__init__()
|
2020-12-19 00:50:17 +08:00
|
|
|
self.info = kwargs
|
2020-12-03 15:07:03 +08:00
|
|
|
|
|
|
|
def __repr__(self):
|
2020-12-19 00:50:17 +08:00
|
|
|
return f"<ActionFailed " + ", ".join(f"{k=}" for k in self.info) + ">"
|
2020-12-03 15:07:03 +08:00
|
|
|
|
|
|
|
def __str__(self):
|
|
|
|
return self.__repr__()
|
2020-12-03 16:04:14 +08:00
|
|
|
|
|
|
|
|
|
|
|
class NetworkError(BaseNetworkError, CQHTTPAdapterException):
|
|
|
|
"""
|
|
|
|
:说明:
|
|
|
|
|
|
|
|
网络错误。
|
|
|
|
|
|
|
|
:参数:
|
|
|
|
|
|
|
|
* ``retcode: Optional[int]``: 错误码
|
|
|
|
"""
|
|
|
|
|
|
|
|
def __init__(self, msg: Optional[str] = None):
|
|
|
|
super().__init__()
|
|
|
|
self.msg = msg
|
|
|
|
|
|
|
|
def __repr__(self):
|
|
|
|
return f"<NetWorkError message={self.msg}>"
|
|
|
|
|
|
|
|
def __str__(self):
|
|
|
|
return self.__repr__()
|
|
|
|
|
|
|
|
|
|
|
|
class ApiNotAvailable(BaseApiNotAvailable, CQHTTPAdapterException):
|
|
|
|
pass
|