From 2f87519faabb3cb5e24679a8c1f7159a01bc569a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=A2=A8=E6=A2=93=E6=9F=92?= <1787882683@qq.com> Date: Wed, 26 Nov 2025 23:02:04 +0800 Subject: [PATCH] =?UTF-8?q?feat=EF=BC=9A=E4=BF=AE=E6=94=B9=E6=A8=A1?= =?UTF-8?q?=E5=9E=8B=E5=88=97=E8=A1=A8=E8=8E=B7=E5=8F=96=E9=94=99=E8=AF=AF?= =?UTF-8?q?=E5=A4=84=E7=90=86=EF=BC=8C=E7=BB=9F=E4=B8=80=E4=BD=BF=E7=94=A8?= =?UTF-8?q?502=E7=8A=B6=E6=80=81=E7=A0=81=E5=93=8D=E5=BA=94?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/webui/model_routes.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/webui/model_routes.py b/src/webui/model_routes.py index 39c2244e..af8fa9a7 100644 --- a/src/webui/model_routes.py +++ b/src/webui/model_routes.py @@ -121,16 +121,18 @@ async def _fetch_models_from_provider( except httpx.TimeoutException: raise HTTPException(status_code=504, detail="请求超时,请稍后重试") except httpx.HTTPStatusError as e: + # 注意:使用 502 Bad Gateway 而不是原始的 401/403, + # 因为前端的 fetchWithAuth 会把 401 当作 WebUI 认证失败处理 if e.response.status_code == 401: - raise HTTPException(status_code=401, detail="API Key 无效或已过期") + raise HTTPException(status_code=502, detail="API Key 无效或已过期") elif e.response.status_code == 403: - raise HTTPException(status_code=403, detail="没有权限访问模型列表") + raise HTTPException(status_code=502, detail="没有权限访问模型列表,请检查 API Key 权限") elif e.response.status_code == 404: - raise HTTPException(status_code=404, detail="该提供商不支持获取模型列表") + raise HTTPException(status_code=502, detail="该提供商不支持获取模型列表") else: raise HTTPException( - status_code=e.response.status_code, - detail=f"请求失败: {e.response.text}" + status_code=502, + detail=f"上游服务请求失败 ({e.response.status_code}): {e.response.text[:200]}" ) except Exception as e: logger.error(f"获取模型列表失败: {e}")