mirror of
https://github.com/nonebot/nonebot2.git
synced 2025-07-28 08:41:29 +00:00
🚧 update ding adapter
This commit is contained in:
@ -1,4 +1,8 @@
|
||||
from nonebot.exception import AdapterException, ActionFailed, ApiNotAvailable
|
||||
from nonebot.typing import Optional
|
||||
from nonebot.exception import (AdapterException, ActionFailed as
|
||||
BaseActionFailed, ApiNotAvailable as
|
||||
BaseApiNotAvailable, NetworkError as
|
||||
BaseNetworkError)
|
||||
|
||||
|
||||
class DingAdapterException(AdapterException):
|
||||
@ -6,22 +10,27 @@ class DingAdapterException(AdapterException):
|
||||
:说明:
|
||||
|
||||
钉钉 Adapter 错误基类
|
||||
|
||||
"""
|
||||
|
||||
def __init__(self) -> None:
|
||||
super().__init__("ding")
|
||||
|
||||
|
||||
class ApiError(DingAdapterException, ActionFailed):
|
||||
class ActionFailed(BaseActionFailed, DingAdapterException):
|
||||
"""
|
||||
:说明:
|
||||
|
||||
API 请求返回错误信息。
|
||||
|
||||
:参数:
|
||||
|
||||
* ``errcode: Optional[int]``: 错误码
|
||||
* ``errmsg: Optional[str]``: 错误信息
|
||||
"""
|
||||
|
||||
def __init__(self, errcode: int, errmsg: str):
|
||||
def __init__(self,
|
||||
errcode: Optional[int] = None,
|
||||
errmsg: Optional[str] = None):
|
||||
super().__init__()
|
||||
self.errcode = errcode
|
||||
self.errmsg = errmsg
|
||||
@ -30,12 +39,37 @@ class ApiError(DingAdapterException, ActionFailed):
|
||||
return f"<ApiError errcode={self.errcode} errmsg={self.errmsg}>"
|
||||
|
||||
|
||||
class SessionExpired(DingAdapterException, ApiNotAvailable):
|
||||
class ApiNotAvailable(BaseApiNotAvailable, DingAdapterException):
|
||||
pass
|
||||
|
||||
|
||||
class NetworkError(BaseNetworkError, DingAdapterException):
|
||||
"""
|
||||
:说明:
|
||||
|
||||
网络错误。
|
||||
|
||||
:参数:
|
||||
|
||||
* ``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 SessionExpired(BaseApiNotAvailable, DingAdapterException):
|
||||
"""
|
||||
:说明:
|
||||
|
||||
发消息的 session 已经过期。
|
||||
|
||||
"""
|
||||
|
||||
def __repr__(self) -> str:
|
||||
|
Reference in New Issue
Block a user