[英]How to remove the console errors in axios?
这是我的代码:
async [types.GET_DATA]({commit, state}, data) {
try {
const res = await axios.post('/login', {
email: data.email,
password: data.password,
});
console.log(res)
} catch(e) {
if(e.response) {
console.log(e.response)
}
}
}
因此,每当用户发送空字段时,我都会返回 400 Bad Request。 axios 所做的是将错误与错误响应一起抛出。 我需要做的是删除该控制台错误消息,只得到错误响应。
我该怎么做?
如果有错误,您可以像这样捕获它:
axios.get("https://google.com").then(response => {
console.log("Done");
}).catch(err => {
console.log("Error");
})
async [types.GET_DATA]({commit, state}, data) {
try {
const res = await axios.post('/login', {
email: data.email,
password: data.password
});
console.log(res)
} catch(err) {
console.log(err)
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.