exceptions.py 1.02 KB
"""自定义异常模块."""


class EmbeddingServiceError(Exception):
    """Embedding服务基础异常."""

    def __init__(self, message: str, code: str = "EMBEDDING_ERROR"):
        self.message = message
        self.code = code
        super().__init__(self.message)


class EmbeddingAPIError(EmbeddingServiceError):
    """Embedding API调用异常."""

    def __init__(self, message: str, status_code: int = 500):
        super().__init__(message, code="EMBEDDING_API_ERROR")
        self.status_code = status_code


class DatabaseError(EmbeddingServiceError):
    """数据库操作异常."""

    def __init__(self, message: str):
        super().__init__(message, code="DATABASE_ERROR")


class NotFoundError(EmbeddingServiceError):
    """资源不存在异常."""

    def __init__(self, message: str):
        super().__init__(message, code="NOT_FOUND")


class ValidationError(EmbeddingServiceError):
    """参数校验异常."""

    def __init__(self, message: str):
        super().__init__(message, code="VALIDATION_ERROR")