feat: 异常树 error_code 类属性(对齐 api-design §7 错误码)

This commit is contained in:
lhl
2026-08-09 13:38:59 +08:00
parent a0a40afd45
commit f61e7dadb7
3 changed files with 23 additions and 3 deletions
+6 -1
View File
@@ -3,19 +3,24 @@ from __future__ import annotations
class LLMError(Exception):
"""LLM 调用相关的异常基类(api-design §7 映射基底)"""
error_code: str | None = None # api §7 错误码(机器可读);新增子类必须覆写
class LLMNetworkError(LLMError):
"""网络失败 / 5xx 重试耗尽(可重试语义)"""
error_code = "LLM_NETWORK_ERROR"
class LLMTimeoutError(LLMError):
"""LLM 调用超时(api-error: LLM_TIMEOUT 502"""
error_code = "LLM_TIMEOUT"
class LLMNotConfiguredError(LLMError):
"""Key / 模型缺失(api-error: LLM_NOT_CONFIGURED 503"""
error_code = "LLM_NOT_CONFIGURED"
class LLMResponseError(LLMError):
"""响应结构损坏(JSON 解析失败等)"""
"""响应结构损坏(JSON 解析失败等)"""
error_code = "LLM_PARSE_ERROR"