fix(gateway): 适配器瞬时错误消息脱敏——只留类名+状态码不泄漏厂商响应体(CR-M2-2)
This commit is contained in:
@@ -23,6 +23,22 @@ def _is_transient_status(status: object) -> bool:
|
||||
)
|
||||
|
||||
|
||||
def provider_error_summary(exc: Exception) -> str:
|
||||
"""脱敏摘要:只含异常类名 + 可选状态码,绝不含原始厂商 HTTP 响应体(CR-M2-2)。
|
||||
|
||||
厂商异常的 `str(exc)` 常内嵌完整响应体(可能含请求内容/内部细节),不应进我们
|
||||
构造并上抛的错误消息(防泄漏,§9.3)。完整细节仍可留在服务端日志(若已记)。
|
||||
状态码优先取 `status_code`,回退取 `code`(Gemini 部分错误用 `exc.code`)。
|
||||
"""
|
||||
name = type(exc).__name__
|
||||
status = getattr(exc, "status_code", None)
|
||||
if not isinstance(status, int):
|
||||
status = getattr(exc, "code", None)
|
||||
if isinstance(status, int):
|
||||
return f"{name} (status={status})"
|
||||
return name
|
||||
|
||||
|
||||
def is_transient_by_name(
|
||||
exc: Exception, names: frozenset[str], *, extra_codes: bool = False
|
||||
) -> bool:
|
||||
|
||||
Reference in New Issue
Block a user