【发布时间】:2018-04-08 20:17:33
【问题描述】:
我有一个使用 Firebase 身份验证来更新用户电子邮件的功能:
export const updateEmail = async (email) => {
const user = auth.currentUser;
return user.updateEmail(email);
};
它用于从表单(在 React 中)获取电子邮件并尝试更新电子邮件的函数中。如果出现错误,我们会更改状态以反映这一点。
handleSave = (e) => {
const email = e.target.email.value;
updateEmail(email).catch((err) => {
this.setState({ didError: true, emailError: err.message });
});
};
我的问题是:为什么这仍然说“未捕获”? handleSave 中的 .catch() 不处理这个问题吗?
更新
【问题讨论】:
-
我没有使用 firebase 的经验,但就从异步函数结果(这是一个承诺)中捕获错误而言,这对我来说看起来不错。
-
你在哪里使用
await? -
@ArupRakshit 你建议我在哪里使用
await? -
您没有在异步函数中返回任何错误。我认为这就是为什么您没有收到任何错误和 error.message 的原因。此外,如前所述,您没有在异步函数中使用 await 。我会尝试添加一个答案。
-
@devserkan 澄清一下,
this.setState()中的错误消息设置正确。
标签: javascript reactjs firebase firebase-authentication