尝试捕获块Axios响应类型是Blob上没有错误消息
获取错误的错误消息
const handleDownloadPicture = async (ids: number) => {
try {
const response = await axios
.post(`/api/folders/${folderDetails.id}/download`, {
resources: ids,
},{responseType:'blob'},
)
.then(({ data: blob }) => {
const link = document.createElement('a');
const url = URL.createObjectURL(blob);
link.href = url;
link.download = 'myfile.zip';
link.click();
});
} catch (error) {
console.error(error);
}
};
我在console.log(error)上收到错误的错误消息
尝试将BLOB响应转换为JSON的多种解决方案,但没有结果
Getting wrong error message
const handleDownloadPicture = async (ids: number) => {
try {
const response = await axios
.post(`/api/folders/${folderDetails.id}/download`, {
resources: ids,
},{responseType:'blob'},
)
.then(({ data: blob }) => {
const link = document.createElement('a');
const url = URL.createObjectURL(blob);
link.href = url;
link.download = 'myfile.zip';
link.click();
});
} catch (error) {
console.error(error);
}
};
I'm getting the wrong error message on console.log(error)
have tried multiple solutions of converting blob response to json but no result
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
becasue
axios.post()
是返回承诺,您应该以两种方式使用响应或捕获错误:const wersys =等待Axios.post()
或<代码> axios.post()。然后(响应).catch()。您只能以两种方式使用一次:
案例1:
案例2:
Becasue
axios.post()
is return Promise, you should use once in two way to get response or catch error:const response = await axios.post()
oraxios.post().then(response).catch()
.You should use only once in two way:
Case 1:
Case 2: