Initial commit: AI 知识库文档智能分块工具
This commit is contained in:
34
exceptions.py
Normal file
34
exceptions.py
Normal file
@@ -0,0 +1,34 @@
|
||||
"""异常类型定义"""
|
||||
|
||||
from typing import Optional
|
||||
|
||||
|
||||
class ParseError(Exception):
|
||||
"""文件解析错误:文件损坏、格式不支持、编码无法识别"""
|
||||
|
||||
def __init__(self, file_name: str, reason: str):
|
||||
self.file_name = file_name
|
||||
self.reason = reason
|
||||
super().__init__(f"解析失败 [{file_name}]: {reason}")
|
||||
|
||||
|
||||
class UnsupportedFormatError(ParseError):
|
||||
"""不支持的文件格式"""
|
||||
|
||||
def __init__(self, file_name: str, extension: str):
|
||||
self.extension = extension
|
||||
super().__init__(file_name, f"不支持的文件格式: {extension}")
|
||||
|
||||
|
||||
class ApiError(Exception):
|
||||
"""DeepSeek API 调用错误"""
|
||||
|
||||
def __init__(self, message: str, status_code: Optional[int] = None):
|
||||
self.status_code = status_code
|
||||
super().__init__(message)
|
||||
|
||||
|
||||
class RateLimitError(ApiError):
|
||||
"""API 速率限制错误(HTTP 429)"""
|
||||
|
||||
pass
|
||||
Reference in New Issue
Block a user