gpt4 book ai didi

javascript - console.log 中出现 Axios Stop 404 错误

转载 作者:行者123 更新时间:2023-12-01 15:10:08 29 4
gpt4 key购买 nike

我正在通过 Axios 检查资源是否存在,如果不存在,则期望返回 404 是正常的。

但是,当返回 404 时,它会显示在控制台中。我试图捕捉错误,但这并不能阻止它被 chrome 显示。

        axios.get('/api/user/checkin').then((response) => {
Vue.set(UserStore,'checkin', response.data)
this.loading = false;
}).catch((error) =>{})

我正在检查用户是否被检查,我将返回他们 checkin 时间的记录以及网站上的一些详细信息。

如果不是,那么我没有什么可返回的,所以我返回 404。我可以返回一个空白记录,但这确实让人感到非常放松。

最佳答案

这是 Chrome 行为 .见 thisalso this .
你可以做console.clear()捕获 根据 this answer 的建议.

axios.get('/api/user/checkin')
.then((response) => {
Vue.set(UserStore,'checkin', response.data)
this.loading = false;
})
.catch(() => console.clear()) // this will clear any console errors caused by this request

或者
.catch(console.clear)简而言之。

但请注意,您将丢失任何以前的控制台日志 .

编辑:

您可能希望仅在收到 404 响应时清除控制台。

axios.get('/api/user/checkin')
.then((response) => {
Vue.set(UserStore,'checkin', response.data)
this.loading = false;
})
.catch((error) => {
if(error.response && error.response.status === 404) {
console.clear();
}
})

引用 handling errors in Axios更多。

关于javascript - console.log 中出现 Axios Stop 404 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57372171/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com