接口报错异常处理

This commit is contained in:
董宏凯 committed 2026-05-18 23:06:59 +08:00
1 parent 73e76fc72f
commit 2c56a84bb7
4 files changed
+65 -9

No files matched your search

@@ -21,9 +21,15 @@ logger = logging.getLogger(__name__)
_MAX_MATERIALS = 12
def _notice(title: str, detail: str) -> dict:
"""构造一个非致命告警事件,前端在时间线显示「标题 + 真实原因」,不打断写作流程。"""
return {"type": "notice", "agent_name": "素材收集专家", "title": title, "detail": detail}
def _notice(title: str, detail: str, raw: str = "") -> dict:
"""构造一个非致命告警事件,前端在时间线显示「标题 + 真实原因」,不打断写作流程。
raw 非空时附带接口的原始错误响应体,前端默认折叠展示。
"""
event = {"type": "notice", "agent_name": "素材收集专家", "title": title, "detail": detail}
if raw:
event["raw"] = raw
return event
async def researcher_node(state: AIWritingState, config: RunnableConfig) -> dict:
@@ -173,7 +179,13 @@ async def researcher_node(state: AIWritingState, config: RunnableConfig) -> dict
notices.append(_notice("模型错误", f"素材排序失败,已按相关度兜底排序。原因:{rank_error}"))
if search_errors:
uniq = list(dict.fromkeys(search_errors))
notices.append(_notice("ES 波动导致检索异常", ";".join(uniq[:3])))
# 解析失败时收集到的接口原始响应体,前端折叠展示便于定位
raw_dumps = list(dict.fromkeys(getattr(provider, "raw_responses", []) or []))
notices.append(_notice(
"ES 波动导致检索异常",
";".join(uniq[:3]),
raw="\n\n----------\n\n".join(raw_dumps[:3]),
))
return {
"material_package": pkg,