【发布时间】:2020-08-24 06:00:45
【问题描述】:
我正在尝试在电子邮件发送或失败时显示警报消息。如果失败,我会从后端得到 403。但不知道如何在客户端显示它。如果成功,我得到一个 200。现在,在失败的情况下,如果我 console.log(res)(如下所示),它显示
res is not defined
Uncaught (in promise) Error: Request failed with status code 403
在网络选项卡中,我得到了响应。没关系。
我只想在我的反应组件中显示它的客户端。
handleClick = (id) => {
axios
.post(`http://localhost:3000/api/v1/users/send-post/${id}`)
.then((res) =>
console.log(res),
res.status === 200 ? alert("Email sent"): null
)
.catch((err) => {
if (err) {
return alert("Sorry, Something went wrong")
}
})
}
【问题讨论】:
标签: javascript node.js reactjs express promise