互联网技术 · 2024年2月15日

如何在设置了responseType:Blob后获取返回的JSON错误信息?

当我们将请求类型设置为responseType: ‘blob’时,什么是Blob呢,MDN官方解释:Blob 对象表示一个不可变、原始数据的类文件对象。我们会发现正常获取错误信息返回时,拿不到错误信息,但是在控制台可以正常看到,这时我们需要将错误信息处理一下。

请求设置:

async getExperienceQRCode(formDate) {

return await $axios.$post(`/admin/wx-open-platform/qrcode`,JSON.stringify(formDate),{ responseType: blob})

},

错误返回处理:

if (error.response.request.responseType && error.response.request.responseType == blob)

{

let reader = new FileReader()

reader.onload = e => {

let errData = JSON.parse(e.target.result)

Vue.prototype.$message.error(errData.data);

}

reader.readAsText(error.response.data)

}

文章来源:田珊珊个人博客

来源地址:http://www.tianshan277.com/849.html

申请创业报道,分享创业好点子。

OpenMagic API

Need more than content? Move into the product flow.

If you are here for model access, pricing, developer docs, or the future API console, the dedicated product path now lives on api.openmagic.ai.

登录免费注册