diff --git a/js/upload/main.ts b/js/upload/main.ts index 6983920a47..c0730ba233 100644 --- a/js/upload/main.ts +++ b/js/upload/main.ts @@ -15,6 +15,7 @@ import { handleSuccessParams, UploadTriggerUploadText, ErrorContext, + ResponseType, } from './types'; export interface BeforeUploadExtra { @@ -67,13 +68,15 @@ export interface OnErrorParams extends ErrorContext { export function handleError(options: OnErrorParams) { const { event, files, response, XMLHttpRequest, formatResponse } = options; - files.forEach((file) => { - file.status = 'fail'; - }); let res = response; if (isFunction(formatResponse)) { res = formatResponse(response, { file: files[0], currentFiles: files }); } + files.forEach((file) => { + file.status = 'fail'; + file.response = res; + }); + return { response: res, event, files, XMLHttpRequest }; } @@ -146,7 +149,15 @@ export function uploadOneRequest(params: HandleUploadParams): Promise; +export type ResponseType = { error?: string; url?: string; status?: 'fail' | 'success'; files?: UploadFile[] } & Record export interface HandleUploadParams { /** 已经上传过的文件 */