reactjs - 如何在反应 js 中捕获 net::ERR_CONNECTION_TIMED_OUT?
问题描述
我是 React js 的初学者。我在控制台中收到此错误。但我想向用户显示这个错误。这是我的简约代码:
const [error, setError] = useState("");
try {
Axios.post('http://10.20.2.3:5000/accounts/login', {
email,
password
}).then(response =>{
if (response.status == "201") {
history.push("/admin/dashboard");
}
}).catch(error => {
if (error.response) {
setError(error.response.data.message);
setLoading(false);
}
}).then(function () {
});
} catch (e) {
setError(e.response.data.message);
}
<Alert color="danger" isOpen={ error != ""} fade={true}>
{ error }
</Alert>
我是否应该使用 try catch 来显示此类错误。我怀疑我的 try catch 块不正确。
任何人都可以帮忙吗?
解决方案
推荐阅读
- android - 如何在Android中将标签和textView组合在一起?
- azure-ad-b2c - B2C 是否有办法从外部身份提供者中提取表单发布的字段?
- visual-studio-code - ESLint 没有运行,因为不推荐使用的设置 'eslint.enable' 设置为 false。删除设置并使用扩展禁用功能
- python - 如何将某些数字添加到 python 列表中的列表中?
- sql - 哪个舍入舍入日期时间在 SQL 中更有效
- excel - 如何链接两个excel文件和链接列
- java - 使用 Jackson 反序列化 POJO 的日期字段 - 无法正确反序列化日期字段
- wagtail - ChildPage.objects.child_of(self) 和 ParentPage.get_children() 有什么区别?
- python - 通过 PIP 安装时获取 CWD
- c++ - LNK2019 在 Visual Studio 2019 中链接 google 测试