回传日志去高度限制与文案同步,错误 toast 可展开详情
CI / test (push) Successful in 27s

This commit is contained in:
2026-07-17 16:53:03 +08:00
parent c0229b60c1
commit 3475ce7ce6
3 changed files with 15 additions and 8 deletions
+9 -2
View File
@@ -32,8 +32,15 @@ function buildUrl(path: string, query?: RequestOptions['query']): string {
async function parseError(resp: Response): Promise<never> {
let message = `请求失败(${resp.status})`
try {
const body = (await resp.json()) as { error?: string; hint?: string }
if (body.error) message = body.hint ? `${body.hint}|${body.error}` : body.error
const body = (await resp.json()) as { error?: string; hint?: string; errors?: unknown[] }
if (body.error) {
message = body.hint ? `${body.hint}|${body.error}` : body.error
} else {
// 批量接口(如创建实例)全部失败时返回 errors 数组,逐行合并;
// 调用方以「短标题 + detail」经 useToast 展示,多行在详情块中逐行可读
const list = (body.errors ?? []).filter((e): e is string => typeof e === 'string')
if (list.length) message = list.join('\n')
}
} catch {
/* 非 JSON 响应体,保留默认消息 */
}