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: [
|
transformResponse: [
|
||||||
function (data, headers) {
|
function (data, headers) {
|
||||||
// 在这里可以访问 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 contentType = headers['content-type'];
|
||||||
const contentDisposition = headers['content-disposition']
|
const contentDisposition = headers['content-disposition']
|
||||||
// console.log('Content-Type:', contentType);
|
// console.log('Content-Type:', contentType);
|
||||||
@ -306,7 +317,7 @@ export const exportFile: (
|
|||||||
window.URL.revokeObjectURL(link.href)
|
window.URL.revokeObjectURL(link.href)
|
||||||
}
|
}
|
||||||
return true
|
return true
|
||||||
})
|
}).catch(()=>{})
|
||||||
}
|
}
|
||||||
|
|
||||||
export const exportExcelPost: (
|
export const exportExcelPost: (
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user