背景:接口调用成功时会获取到文件流,如果是报错,错误信息如何获取到呢?
axios({
method: 请求方式,
url: 接口路径,
data: 接口参数,
dataType: 'json',
responseType: 'blob',
}).then(response => {
var reader = new FileReader();
reader.readAsText(res, 'utf-8');
reader.onload = function () {
if (res.type === 'application/json') {
const jsonData = JSON.parse(reader.result) // 说明是普通对象数据,后台转换失败
// 后台信息
console.log(jsonData)
if (jsonData.code == 400119) {
}
} else {
console.log('url', URL.createObjectURL(res)) //转化为页面可打开的文件流
}
}
}).catch(error => {