ForcePilot/backend/package/yuxi/channels/application/usecase/failure_detail.py
Kris b88c0ae29e feat(channels): 批量新增多渠道网关限界上下文基础代码与契约
新增完整的 channels 限界上下文模块,包含契约层、领域核心层、应用服务、管道编排、插件体系、基础设施组合根等全层级代码,新增飞书与微信 iLink 渠道插件基础结构,补充各类 DTO、端口协议与领域服务实现。
2026-07-02 03:22:12 +08:00

45 lines
1.5 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

"""失败详情构造函数D16
抽离 ``ChannelControlService._toFailureDetail`` 与 ``AdminMessageService``
的重复逻辑为模块级函数,供两个 service 复用。
"""
from __future__ import annotations
from yuxi.channels.contract.dtos.common import FailureDetail
from yuxi.channels.contract.errors import Error
__all__ = ["toFailureDetail"]
def toFailureDetail(target: str, err: Error | None) -> FailureDetail:
"""将管道错误转换为失败详情。
当 ``err`` 非空时,使用错误的 ``error_code`` 与 ``message`` 构造失败
详情,并提取 ``err.details`` 业务字段存入 ``details``,供
``raiseOnControlFailure`` 反向重构异常时保留 ``resource`` / ``id`` /
``field`` / ``rule`` 等业务字段;为空时(管道返回失败但未携带错误
对象)使用 ``INTERNAL`` 通用错误码与兜底消息构造。
参数:
target: 失败目标(操作类型 / 投递目标等),写入 ``FailureDetail.target``。
err: 管道返回的错误对象None 时使用通用错误码。
返回:
失败详情。
"""
if err is not None:
return FailureDetail(
target=target,
error_code=err.error_code,
message=err.message,
retryable=False,
details=err.details or None,
)
return FailureDetail(
target=target,
error_code="INTERNAL",
message="pipeline failed without error",
retryable=False,
)