feat(short-drama-agent-front): 完善质量规则确认与中文交互

This commit is contained in:
GJ committed 2026-10-17 22:09:28 +08:00
1 parent 190333d4f9
commit c4b43b9725
85 files changed
+2059 -480

No files matched your search

+13 -8
View File
@@ -1,3 +1,5 @@
import { businessErrorMessages, userFacingText } from './user-facing-text'
/** HTTP 错误携带状态码与后端细节,供页面区别空数据、校验错误与网络故障。 */
export class ApiError extends Error {
constructor(
@@ -57,7 +59,7 @@ export async function request<T>(path: string, options: RequestOptions = {}): Pr
try {
data = text ? JSON.parse(text) : undefined
} catch {
throw new ApiError('接口未返回 JSON,请检查 API 地址与代理配置。', response.status)
throw new ApiError('服务暂时无法返回有效结果,请稍后重试。', response.status)
}
if (!response.ok) {
const message =
@@ -75,7 +77,7 @@ export async function request<T>(path: string, options: RequestOptions = {}): Pr
if (options.signal?.aborted) throw error
if (controller.signal.aborted)
throw new ApiError('请求等待超时。后台任务可能仍在运行,请先刷新状态,不要重复提交。', 0)
throw new ApiError('无法连接后端。请检查服务与代理;已提交的任务可能仍在运行。', 0)
throw new ApiError('暂时无法连接服务,请检查网络后重试;已提交的任务可能仍在运行。', 0)
} finally {
clearTimeout(timer)
options.signal?.removeEventListener('abort', abort)
@@ -92,11 +94,14 @@ export async function optionalResource<T>(promise: Promise<T>): Promise<T | null
}
}
/** 页面统一显示可操作的错误信息。 */
/**
* 页面统一显示业务原因,原始错误与详情仍保留供程序判断和导出。
* @param error 原始请求或操作错误
* @returns 普通用户可理解的原因和处理建议
*/
export function errorMessage(error: unknown): string {
if (error instanceof ApiError && error.details) {
const details = typeof error.details === 'string' ? error.details : JSON.stringify(error.details)
return `${error.message} ${details}`
}
return error instanceof Error ? error.message : '操作失败,请刷新后重试。'
const fallback = '操作失败,请刷新后重试。'
if (error instanceof ApiError)
return [...new Set([userFacingText(error.message, fallback), ...businessErrorMessages(error.details)].filter(Boolean))].join(';') || fallback
return error instanceof Error ? userFacingText(error.message, fallback) || fallback : fallback
}