WIP-CHECKPOINT[auth-refactor]: 固化工程师崩溃前部分成果 + 同树其他未提交WIP(仅源码,不含密钥/二进制)-- 待重激活工程师续作
This commit is contained in:
@@ -0,0 +1,40 @@
|
||||
# =============================================================================
|
||||
# 企微IT智能服务台 — 阶段5 自动化 异常定义
|
||||
# =============================================================================
|
||||
# 说明:定义自动化引擎内部异常 AutomationException(携带数值错误码),
|
||||
# 以及 to_app_exception 转换为项目统一的 AppException,
|
||||
# 使全局异常处理器能输出 {code, data, message} 标准格式。
|
||||
# =============================================================================
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from typing import Any, Optional
|
||||
|
||||
from app.constants import AutomationErrorCode, automation_error_message
|
||||
from app.utils.response import AppException
|
||||
|
||||
|
||||
class AutomationException(Exception):
|
||||
"""自动化引擎内部异常。
|
||||
|
||||
Attributes:
|
||||
code: 自动化错误码(AutomationErrorCode 取值)
|
||||
message: 错误消息(缺省取错误码默认文案)
|
||||
data: 附加数据
|
||||
"""
|
||||
|
||||
def __init__(self, code: int, message: str = "", data: Any = None):
|
||||
self.code = code
|
||||
self.message = message or automation_error_message(code)
|
||||
self.data = data
|
||||
super().__init__(self.message)
|
||||
|
||||
|
||||
def to_app_exception(exc: AutomationException) -> AppException:
|
||||
"""将 AutomationException 转为项目统一的 AppException。"""
|
||||
return AppException(code=exc.code, message=exc.message, data=exc.data)
|
||||
|
||||
|
||||
def automation_error_code(code: int) -> int:
|
||||
"""校验并返回合法的错误码(占位,便于未来扩展白名单)。"""
|
||||
return code
|
||||
Reference in New Issue
Block a user