66 lines
1.8 KiB
Python
66 lines
1.8 KiB
Python
"""
|
|
CookieCloud客户端异常类
|
|
"""
|
|
|
|
|
|
class CookieCloudError(Exception):
|
|
"""CookieCloud基础异常类"""
|
|
|
|
def __init__(self, message: str, details: dict = None):
|
|
self.message = message
|
|
self.details = details or {}
|
|
super().__init__(self.message)
|
|
|
|
def __str__(self):
|
|
if self.details:
|
|
return f"{self.message} - 详情: {self.details}"
|
|
return self.message
|
|
|
|
|
|
class ConfigurationError(CookieCloudError):
|
|
"""配置错误异常"""
|
|
|
|
def __init__(self, message: str, config_key: str = None):
|
|
details = {'config_key': config_key} if config_key else {}
|
|
super().__init__(message, details)
|
|
|
|
|
|
class ConnectionError(CookieCloudError):
|
|
"""连接错误异常"""
|
|
|
|
def __init__(self, message: str, server: str = None, status_code: int = None):
|
|
details = {}
|
|
if server:
|
|
details['server'] = server
|
|
if status_code:
|
|
details['status_code'] = status_code
|
|
super().__init__(message, details)
|
|
|
|
|
|
class AuthenticationError(CookieCloudError):
|
|
"""认证错误异常"""
|
|
|
|
def __init__(self, message: str, username: str = None):
|
|
details = {'username': username} if username else {}
|
|
super().__init__(message, details)
|
|
|
|
|
|
class DataParseError(CookieCloudError):
|
|
"""数据解析错误异常"""
|
|
|
|
def __init__(self, message: str, raw_data: str = None):
|
|
details = {}
|
|
if raw_data:
|
|
details['raw_data_length'] = len(raw_data)
|
|
super().__init__(message, details)
|
|
|
|
|
|
class NetworkError(CookieCloudError):
|
|
"""网络错误异常"""
|
|
|
|
def __init__(self, message: str, original_error: Exception = None):
|
|
details = {}
|
|
if original_error:
|
|
details['original_error'] = str(original_error)
|
|
super().__init__(message, details)
|