我正在尝试捕获我在后端创建的自定义错误,但是 Axios 和 fetch 没有得到res.status(401).json({msg:"custom error name"}) 我已经从 catch 得到响应但是没有错误没有消息
try {
const loginUser = { email: user.email, password: user.password };
const loginRes = await Axios.post(
"http://localhost:4000/snackhub/login",
loginUser
);
localStorage.setItem("auth-token", loginRes.data.token);
dispatch(fetchUsers());
history.push("/");
} catch (err) {
console.log(err.response);
err.response.data.msg && console.log(err.response.data.msg); //hopefully i can display this thhe custom error from the backend
}
以下是后端错误的示例:
const { error } = await logInValidation(req.body);
if (error) return res.status(400).json({ msg: error.message[0].details }); //is there something wrong in my syntax here?
const userExists = await Customer.findOne({ email: email });
if (!userExists)
return res.status(400).json({ msg: "email is not registered" });
狐的传说
素胚勾勒不出你
弑天下
守着星空守着你
梵蒂冈之花
随时随地看视频慕课网APP
相关分类