fix(short-drama-agent-front): 修复资产库请求与管理流程
This commit is contained in:
1 parent
41d1cfe3ed
commit
f8b0fbb8ca
10 files changed
+672
-77
No files matched your search
+18
-2
@@ -27,6 +27,17 @@ function isRecord(value: unknown): value is Record<string, unknown> {
|
||||
return typeof value === 'object' && value !== null && !Array.isArray(value)
|
||||
}
|
||||
|
||||
/**
|
||||
* 网关中断可能发生在操作已提交后,说明恢复方式但不自动重试写入。
|
||||
* @param status 原始HTTP状态
|
||||
* @returns 网关连接提示,普通业务错误返回undefined
|
||||
*/
|
||||
function gatewayErrorMessage(status: number): string | undefined {
|
||||
return [502, 503, 504].includes(status)
|
||||
? '服务连接暂时中断,请重新连接;已提交的操作请先刷新结果后核对。'
|
||||
: undefined
|
||||
}
|
||||
|
||||
/**
|
||||
* 解析公开响应及顶层同步错误码,不自动重试写入。
|
||||
* @param path 不含统一 API 前缀的正式路径
|
||||
@@ -59,11 +70,16 @@ export async function request<T>(path: string, options: RequestOptions = {}): Pr
|
||||
try {
|
||||
data = text ? JSON.parse(text) : undefined
|
||||
} catch {
|
||||
throw new ApiError('服务暂时无法返回有效结果,请稍后重试。', response.status)
|
||||
throw new ApiError(
|
||||
gatewayErrorMessage(response.status) ?? '服务暂时无法返回有效结果,请稍后重试。',
|
||||
response.status
|
||||
)
|
||||
}
|
||||
if (!response.ok) {
|
||||
const message =
|
||||
isRecord(data) && typeof data.message === 'string' ? data.message : `请求失败(${response.status})`
|
||||
isRecord(data) && typeof data.message === 'string' && data.message.trim()
|
||||
? data.message
|
||||
: (gatewayErrorMessage(response.status) ?? `请求失败(${response.status})`)
|
||||
throw new ApiError(
|
||||
message,
|
||||
response.status,
|
||||
|
||||
Reference in new issue
Block a user