本次同步 09-12 至 09-28 的代码变更,主要内容: 新增功能 - 修改密码:后端新增 ChangePasswordRequest DTO 与UserController/UserService 对应接口,前端新增 ChangePasswordDialog 并在 Header 接入入口 - 文件预览组件重构:file-preview 目录拆分出 VideoPreview(支持 blobUrl 直传)、 ImagePreview、AudioPreview,index.tsx 统一调度各类型预览器 - 新增 my_ops 算子模块:markitdown_parser、mineru_pdf_parser、text_quality_evaluator - 新增 tools/minio-file-server MinIO 文件服务 功能增强 - 数据清洗:cleaning_task_service/scheduler/routes 重构, data_juicer_executor 与 wrapper 增强,OperatorTable/LogsTable/TaskDetail 同步调整 - 数据标注:annotation sync.py、project.py 接口与schema 更新 - 数据采集、算子市场、首页与菜单路由相关页面调整 - DataJuicer 算子接入(useOperatorOperations、dj_ops_schema) 结构调整 - deepflow/ 更名为 deep-flow/(419 个文件重命名) - 新增 helm 部署编排、GitHub Actions 之外的自建镜像构建脚本 未纳入本次提交 - scripts-backup/、runtime/python-executor-backup/、components_backup/(备份目录) - *.backup*、__pycache__ 产物 - zh_core_web_sm-3.8.0-py3-none-any.whl(46MB 构建产物) - DataX/(内嵌独立仓库,远程亦未收录其源码)
126 lines
3.1 KiB
Python
126 lines
3.1 KiB
Python
"""
|
||
基础异常类和错误码定义
|
||
"""
|
||
from typing import Any
|
||
from dataclasses import dataclass
|
||
|
||
|
||
@dataclass(frozen=True)
|
||
class ErrorCode:
|
||
"""
|
||
不可变的错误码定义
|
||
|
||
属性:
|
||
code: 错误码字符串(如 "annotation.0001")
|
||
message: 人类可读的错误消息
|
||
http_status: HTTP状态码(业务错误默认为400)
|
||
"""
|
||
code: str
|
||
message: str
|
||
http_status: int = 400
|
||
|
||
def __post_init__(self):
|
||
"""验证错误码格式"""
|
||
if not isinstance(self.code, str):
|
||
raise ValueError(f"错误码必须是字符串,实际类型: {type(self.code)}")
|
||
if not self.code:
|
||
raise ValueError("错误码不能为空")
|
||
|
||
|
||
class BaseError(Exception):
|
||
"""
|
||
所有应用异常的基类
|
||
|
||
所有自定义异常都应该继承此类。
|
||
提供自动的错误码和消息处理。
|
||
|
||
使用示例:
|
||
raise BusinessError(ErrorCodes.TASK_NOT_FOUND)
|
||
|
||
客户端将收到:
|
||
{
|
||
"code": "annotation.0001",
|
||
"message": "任务不存在",
|
||
"data": null
|
||
}
|
||
"""
|
||
|
||
def __init__(
|
||
self,
|
||
error_code: ErrorCode,
|
||
data: Any = None,
|
||
*args: Any
|
||
):
|
||
"""
|
||
使用错误码和可选数据初始化异常
|
||
|
||
Args:
|
||
error_code: ErrorCode 实例
|
||
data: 附加错误数据(会包含在响应中)
|
||
*args: 额外参数(用于兼容性)
|
||
"""
|
||
self.error_code = error_code
|
||
self.data = data
|
||
super().__init__(error_code.message, *args)
|
||
|
||
@property
|
||
def code(self) -> str:
|
||
"""获取错误码字符串"""
|
||
return self.error_code.code
|
||
|
||
@property
|
||
def message(self) -> str:
|
||
"""获取错误消息"""
|
||
return self.error_code.message
|
||
|
||
@property
|
||
def http_status(self) -> int:
|
||
"""获取HTTP状态码"""
|
||
return self.error_code.http_status
|
||
|
||
def to_dict(self) -> dict:
|
||
"""将异常转换为响应字典"""
|
||
msg = self.message
|
||
if self.data and isinstance(self.data, str):
|
||
msg = f"{msg},detail:{self.data}"
|
||
|
||
return {
|
||
"code": self.code,
|
||
"message": msg, #self.message,
|
||
"data": self.data
|
||
}
|
||
|
||
|
||
class SystemError(BaseError):
|
||
"""
|
||
系统级异常(意外错误)
|
||
|
||
用于:
|
||
- 数据库错误
|
||
- 网络错误
|
||
- 配置错误
|
||
- 编程错误(bug)
|
||
|
||
系统错误会记录完整的堆栈跟踪
|
||
"""
|
||
|
||
def __init__(self, error_code: ErrorCode, data: Any = None):
|
||
super().__init__(error_code, data)
|
||
|
||
|
||
class BusinessError(BaseError):
|
||
"""
|
||
业务逻辑异常(预期内的错误)
|
||
|
||
用于:
|
||
- 验证失败
|
||
- 资源不存在
|
||
- 权限不足
|
||
- 业务规则违反
|
||
|
||
业务错误不记录堆栈跟踪(因为它们是预期的)
|
||
"""
|
||
|
||
def __init__(self, error_code: ErrorCode, data: Any = None):
|
||
super().__init__(error_code, data)
|