fix: 功能修改完善。

This commit is contained in:
tianyongbao
2026-07-06 00:37:01 +08:00
parent 9027869e97
commit 6846ea3e0f
7 changed files with 132 additions and 22 deletions

View File

@@ -31,7 +31,16 @@ const upload = <T>(config: RequestUploadConfig): Promise<ResponseData<T>> => {
header: config.header,
formData: config.formData,
success: (res) => {
let result = JSON.parse(res.data)
let result
// 后端可能返回 JSON 字符串(正常)或 HTML 错误页(如 413 Payload Too Large
// 必须包 try-catch否则 JSON.parse 招错后 Promise 永远不 settlemask loading 永不关闭
try {
result = JSON.parse(res.data)
} catch (e) {
toast('上传失败:服务器响应非 JSON 格式(可能文件过大)')
reject('上传失败:响应解析失败')
return
}
const code = result.code || 200
// @ts-ignore
const msg = errorCode[code] || result.msg || errorCode['default']