Skip to content

Commit a35ddad

Browse files
committed
fix: handle JSON response error in exportFile function
1 parent bc350c2 commit a35ddad

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

ui/src/request/index.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,17 @@ export const exportFile: (
282282
transformResponse: [
283283
function (data, headers) {
284284
// 在这里可以访问 headers
285+
if (data.type === 'application/json') {
286+
data.text().then((text: string) => {
287+
try {
288+
const json = JSON.parse(text)
289+
MsgError(json.message || text)
290+
} catch {
291+
MsgError(text)
292+
}
293+
})
294+
throw new Error('Response is not a valid file')
295+
}
285296
// const contentType = headers['content-type'];
286297
const contentDisposition = headers['content-disposition']
287298
// console.log('Content-Type:', contentType);
@@ -306,7 +317,7 @@ export const exportFile: (
306317
window.URL.revokeObjectURL(link.href)
307318
}
308319
return true
309-
})
320+
}).catch(()=>{})
310321
}
311322

312323
export const exportExcelPost: (

0 commit comments

Comments
 (0)