feat(ui): 优化上游模型查询错误提示

新增 parseUpstreamModelError 函数,将后端返回的原始错误信息
转换为用户友好的中文提示,支持解析 HTTP 状态码和 JSON 错误体
This commit is contained in:
fawney19
2026-01-11 00:41:41 +08:00
parent aec0326d40
commit 8d8b20aa47
4 changed files with 137 additions and 8 deletions

View File

@@ -334,7 +334,7 @@ import {
} from 'lucide-vue-next'
import { Dialog, Button, Input, Checkbox, Badge } from '@/components/ui'
import { useToast } from '@/composables/useToast'
import { parseApiError } from '@/utils/errorParser'
import { parseApiError, parseUpstreamModelError } from '@/utils/errorParser'
import {
updateProviderKey,
API_FORMAT_LABELS,
@@ -522,11 +522,17 @@ async function fetchUpstreamModels() {
}
collapsedGroups.value = allGroups
} else {
showError(response.data?.error || '获取上游模型失败', '错误')
// 使用友好的错误解析
const errorMsg = response.data?.error
? parseUpstreamModelError(response.data.error)
: '获取上游模型失败'
showError(errorMsg, '获取上游模型失败')
}
} catch (err: any) {
if (loadingCancelled) return
showError(err.response?.data?.detail || '获取上游模型失败', '错误')
// 使用友好的错误解析
const rawError = err.response?.data?.detail || err.message || '获取上游模型失败'
showError(parseUpstreamModelError(rawError), '获取上游模型失败')
} finally {
fetchingUpstreamModels.value = false
}