ForcePilot/backend/package/yuxi/channels/exceptions.py
Kris 7a972055b7 feat: 新增渠道服务基础框架与核心工具类
新增大量渠道适配器相关的协议、策略、工具类与基础设施代码,包括:
1.  多协议定义:认证、消息、配置、网关等核心接口
2.  策略模块:上下文、群聊、去重、防抖等业务策略
3.  工具集:重试、去重、文本分块、消息格式化等SDK工具
4.  基础设施:外部进程管理、事件广播、熔断机制等
5.  账户与管道系统:账户管理、消息处理管道实现
6.  运行时服务:状态收集、维护任务、日志等后台服务
2026-05-12 00:53:57 +08:00

42 lines
1.5 KiB
Python

class ChannelException(Exception):
def __init__(self, message: str, retryable: bool = False, retry_after_ms: int = 0):
super().__init__(message)
self.retryable = retryable
self.retry_after_ms = retry_after_ms
class ChannelNotConnectedError(ChannelException):
def __init__(self):
super().__init__("Channel not connected", retryable=True, retry_after_ms=5000)
class ChannelConnectionError(ChannelException):
def __init__(self, message: str = "Channel connection failed"):
super().__init__(message, retryable=True, retry_after_ms=5000)
class ChannelAuthenticationError(ChannelException):
def __init__(self, message: str = "Channel authentication failed"):
super().__init__(message, retryable=False)
class ChannelRateLimitError(ChannelException):
def __init__(self, retry_after_ms: int = 60000):
super().__init__("Rate limited by channel", retryable=True, retry_after_ms=retry_after_ms)
class TokenExpiredError(ChannelException):
def __init__(self):
super().__init__("Access token expired", retryable=True, retry_after_ms=1000)
class MessageFormatError(ChannelException):
def __init__(self):
super().__init__("Invalid message format", retryable=False)
class DeliveryFailedError(ChannelException):
def __init__(self, message: str = ""):
detail = f"Message delivery failed: {message}" if message else "Message delivery failed"
super().__init__(detail, retryable=True, retry_after_ms=3000)