From a35ddad7f313e0218324b47fbf2fe524168c2a7f Mon Sep 17 00:00:00 2001 From: CaptainB Date: Thu, 10 Jul 2025 21:06:37 +0800 Subject: [PATCH] fix: handle JSON response error in exportFile function --- ui/src/request/index.ts | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/ui/src/request/index.ts b/ui/src/request/index.ts index 6eedbe50b..58d626a2b 100644 --- a/ui/src/request/index.ts +++ b/ui/src/request/index.ts @@ -282,6 +282,17 @@ export const exportFile: ( transformResponse: [ function (data, headers) { // 在这里可以访问 headers + if (data.type === 'application/json') { + data.text().then((text: string) => { + try { + const json = JSON.parse(text) + MsgError(json.message || text) + } catch { + MsgError(text) + } + }) + throw new Error('Response is not a valid file') + } // const contentType = headers['content-type']; const contentDisposition = headers['content-disposition'] // console.log('Content-Type:', contentType); @@ -306,7 +317,7 @@ export const exportFile: ( window.URL.revokeObjectURL(link.href) } return true - }) + }).catch(()=>{}) } export const exportExcelPost: (