mirror of
https://github.com/qingchencloud/clawpanel.git
synced 2026-05-06 20:02:49 +08:00
fix(models): 获取模型列表 404 改为友好提示 + 助手侧走后端绕 CORS
场景:部分服务商(如某些厂商的 Anthropic 兼容接口)不提供 /models 列表接口, 之前会直接显示 HTTP 404 Not Found / Failed to fetch 等技术错误,用户体验差。 - Rust list_remote_models:识别 404/405/501 作为"不支持自动获取"场景, 返回带 [NOT_SUPPORTED] 前缀的友好错误,而非裸 HTTP 状态码 - 模型配置页「获取列表」:识别 [NOT_SUPPORTED] 后弹出引导对话框, 点击「模型」按钮直接进入手动添加流程 - 助手设置页「获取列表」:改为走 Rust 后端 api.listRemoteModels, 原先直接用前端 fetch 会被 WebView CORS 拦截(provider 不返回 CORS 头), 改走后端既绕开 CORS 又能获得一致的友好提示 - Web 模式 dev-api.js 同步 404 识别逻辑,保证桌面 / Web 行为一致 - 补齐 models.fetchNotSupported / assistant.fetchNotSupported 多语言文案
This commit is contained in:
@@ -5654,6 +5654,11 @@ pub async fn list_remote_models(
|
||||
let text = resp.text().await.unwrap_or_default();
|
||||
|
||||
if !status.is_success() {
|
||||
// 404/405/501 = 服务商不支持 /models 接口,给用户友好提示而非技术错误
|
||||
let code = status.as_u16();
|
||||
if code == 404 || code == 405 || code == 501 {
|
||||
return Err("[NOT_SUPPORTED] 该服务商不支持自动获取模型列表,请手动输入模型 ID".to_string());
|
||||
}
|
||||
let msg = extract_error_message(&text, status);
|
||||
return Err(format!("获取模型列表失败: {msg}"));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user