ForcePilot/backend/package/yuxi/channels/exceptions.py

42 lines
1.5 KiB
Python
Raw Normal View History

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)