![](/img/trans.png)
[英]React Native: Possible UNhandled Promise Rejection: Can't find variable: name
[英]Possible Unhandled Promise Rejection: Can't find variable ErrorTitle
我正在嘗試創建一個使用 Firebase 身份驗證的應用程序。 我想更改錯誤消息,因為我覺得錯誤消息對用戶不友好。 我已創建此登錄 function,但出現此錯誤: Possible Unhandled Promise Rejection: ReferenceError: Can't find variable: errorTitle
這是我得到的代碼:
try {
this.setState({
loading: true
});
let user = await auth.signInWithEmailAndPassword(email, password);
if (user) {
this.setState({
loading: false
});
this.props.navigation.navigate('Home');
}
} catch(error) {
switch (error.code) {
case 'auth/invalid-email':
errorTitle = 'Invalid Email';
errorMessage = 'Please enter a valid email address';
break;
case 'auth/user-not-found':
errorTitle = 'No User Found';
errorMessage = 'This email does not exist as a user. Please sign up if you want to gain access.';
break;
case 'auth/wrong-password':
errorTitle = 'Wrong Password';
errorMessage = 'The password is incorrect. Please try again.';
break;
default:
errorTitle = 'Error';
errorMessage = 'An undefined error happened.';
}
this.setState({
loading: false
});
Alert.alert(
errorTitle,
errorMessage,
);
}
我似乎無法理解導致錯誤的原因。 我有一個 try/catch 塊。 這是一個 React Native 應用程序。
據我所知,您沒有在代碼中的任何地方聲明errorTitle
或errorMessage
。 您正在嘗試為不存在的事物分配值。
嘗試在switch
語句上方添加let errorTitle
和let errorMessage
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.