首页 > 解决方案 > 发布请求失败后无法捕获响应

问题描述

我发送这样的请求

try {
 const res = await axios.post('/order', formData)

 console.log(res) --> undefined
 console.log(test1) --> it is on console
}
catch (error) {
 console.log(test2)
}

但由于某种原因,即使我从请求中得到 500,test1 和 undefined 也在控制台上。为什么会发生这种情况,即使它是一个错误。不应该去抓吗?

- - 解决方案 - -

4天后我发现了问题所在。从代码中删除 axios.interceptor 后,一切都按预期工作

标签: javascriptreactjsasync-awaitpromiseaxios

解决方案


推荐阅读