async handleFetch() {
const res =
await idleApi.toSign({
file: 'pdf',
});
console.log(res)
// 错误处理
if(!res.headers['content-disposition']) {
const fileReader = new FileReader()
fileReader.readAsText(new Blob([res.data], { type: 'application/octet-stream' }), 'utf-8')
fileReader.onload = () => {
const msg = JSON.parse(fileReader.result)
console.log(msg?.sys_header?.message) // 错误提示信息,根据接口返回内容不同
}
}
}
- 接口正确返回文件流,打印出来的
res
network中返回的是文件流数据
- 接口报错的情况,打印出来的
res
实际network中的内容