mirror of
https://github.com/1Panel-dev/MaxKB.git
synced 2025-12-26 01:33:05 +00:00
fix: handle JSON response error in exportFile function
This commit is contained in:
parent
bc350c2eb2
commit
a35ddad7f3
|
|
@ -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: (
|
||||
|
|
|
|||
Loading…
Reference in New Issue