mirror of
https://github.com/PaiGramTeam/PaiGram.git
synced 2024-12-26 19:35:37 +00:00
233e7ab58d
Co-authored-by: luoshuijs <luoshuijs@outlook.com> Co-authored-by: Karako <karakohear@gmail.com> Co-authored-by: xtaodada <xtao@xtaolink.cn>
42 lines
1.0 KiB
Python
42 lines
1.0 KiB
Python
from typing import Any, Mapping, Optional
|
|
|
|
|
|
class APIHelperException(Exception):
|
|
pass
|
|
|
|
|
|
class NetworkException(APIHelperException):
|
|
pass
|
|
|
|
|
|
class APIHelperTimedOut(APIHelperException):
|
|
pass
|
|
|
|
|
|
class ResponseException(APIHelperException):
|
|
code: int = 0
|
|
message: str = ""
|
|
|
|
def __init__(self, response: Optional[Mapping[str, Any]] = None, message: Optional[str] = None) -> None:
|
|
if response is None:
|
|
self.message = message
|
|
_message = message
|
|
else:
|
|
self.code = response.get("retcode", self.code)
|
|
self.message = response.get("message", "")
|
|
_message = f"[{self.code}] {self.message}"
|
|
|
|
super().__init__(_message)
|
|
|
|
|
|
class DataNotFoundError(ResponseException):
|
|
def __init__(self):
|
|
message = "response data not find"
|
|
super().__init__(message=message)
|
|
|
|
|
|
class ReturnCodeError(ResponseException):
|
|
def __init__(self):
|
|
message = "response return code error"
|
|
super().__init__(message=message)
|