nonebot2/packages/nonebot-adapter-ding/nonebot/adapters/ding/exception.py

84 lines
1.8 KiB
Python
Raw Normal View History

2020-12-06 02:30:19 +08:00
from typing import Optional
2020-12-03 17:08:16 +08:00
from nonebot.exception import (AdapterException, ActionFailed as
BaseActionFailed, ApiNotAvailable as
BaseApiNotAvailable, NetworkError as
BaseNetworkError)
2020-12-03 00:59:32 +08:00
class DingAdapterException(AdapterException):
2020-12-03 12:08:04 +08:00
"""
:说明:
钉钉 Adapter 错误基类
"""
2020-12-03 00:59:32 +08:00
def __init__(self) -> None:
super().__init__("ding")
2020-12-03 00:59:32 +08:00
2020-12-03 17:08:16 +08:00
class ActionFailed(BaseActionFailed, DingAdapterException):
2020-12-03 00:59:32 +08:00
"""
:说明:
2020-12-03 12:08:04 +08:00
API 请求返回错误信息
2020-12-03 00:59:32 +08:00
2020-12-03 17:08:16 +08:00
:参数:
* ``errcode: Optional[int]``: 错误码
* ``errmsg: Optional[str]``: 错误信息
2020-12-03 00:59:32 +08:00
"""
2020-12-03 17:08:16 +08:00
def __init__(self,
errcode: Optional[int] = None,
errmsg: Optional[str] = None):
2020-12-03 12:22:39 +08:00
super().__init__()
2020-12-03 00:59:32 +08:00
self.errcode = errcode
self.errmsg = errmsg
def __repr__(self):
return f"<ApiError errcode={self.errcode} errmsg=\"{self.errmsg}\">"
2020-12-03 00:59:32 +08:00
2020-12-30 00:36:29 +08:00
def __str__(self):
return self.__repr__()
2020-12-03 00:59:32 +08:00
2020-12-03 17:08:16 +08:00
class ApiNotAvailable(BaseApiNotAvailable, DingAdapterException):
pass
class NetworkError(BaseNetworkError, DingAdapterException):
2020-12-03 12:08:04 +08:00
"""
:说明:
2020-12-03 17:08:16 +08:00
网络错误
:参数:
* ``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__()
2020-12-03 12:08:04 +08:00
2020-12-30 00:36:29 +08:00
class SessionExpired(ApiNotAvailable, DingAdapterException):
2020-12-03 17:08:16 +08:00
"""
:说明:
发消息的 session 已经过期
2020-12-03 12:08:04 +08:00
"""
2020-12-03 00:59:32 +08:00
def __repr__(self) -> str:
return f"<Session Webhook is Expired>"
2020-12-30 00:36:29 +08:00
def __str__(self):
return self.__repr__()