From 889715444bdf1d088d0c0500b7946eab4200d876 Mon Sep 17 00:00:00 2001 From: wwwwwwwww <526125649@qq.com> Date: Wed, 1 Jul 2026 17:49:56 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9ai=E5=88=9B=E4=BD=9C=E5=A4=B1?= =?UTF-8?q?=E8=B4=A5=E5=8E=9F=E5=9B=A0=E6=98=BE=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../app/services/generation_ai_service.py | 30 ++++++++++++------- 1 file changed, 20 insertions(+), 10 deletions(-) diff --git a/video-gen-api/app/services/generation_ai_service.py b/video-gen-api/app/services/generation_ai_service.py index 00ba7e51..3ea852e8 100644 --- a/video-gen-api/app/services/generation_ai_service.py +++ b/video-gen-api/app/services/generation_ai_service.py @@ -362,16 +362,26 @@ def _resolve_error_message(error_message: str | None) -> str | None: return error_message import re - # 匹配 code='InputVideoSensitiveContentDetected.PrivacyInformation' 格式 - match = re.search(r"code='([^']+)'", error_message) - if match: - code = match.group(1) - if code in ARK_ERRORS: - return ARK_ERRORS[code] - else: - parts = error_message.split(":") - if len(parts) >= 2 and parts[1].strip() in ARK_ERRORS: - return ARK_ERRORS[parts[1].strip()] + + # 匹配以下格式中的错误码: + # 1. {'error': {'code': 'XXX', ...}} — str(error_obj) 的 Python dict 形式 + # 2. {"error": {"code": "XXX", ...}} — JSON 形式 + # 3. code='XXX' — 旧格式 + for pattern in [ + r"'code'\s*:\s*'([^']+)'", # 'code': 'XXX' + r'"code"\s*:\s*"([^"]+)"', # "code": "XXX" + r"code='([^']+)'", # code='XXX' + ]: + match = re.search(pattern, error_message) + if match: + code = match.group(1) + if code in ARK_ERRORS: + return ARK_ERRORS[code] + + # 兜底:按冒号分割,检查第二部分是否是已知错误码 + parts = error_message.split(":") + if len(parts) >= 2 and parts[1].strip() in ARK_ERRORS: + return ARK_ERRORS[parts[1].strip()] # 没有匹配到已知错误码时,直接返回"生成失败" return "生成失败"