我正在使用 Android Amplify 库。我无法找出从Amplify.Auth.signIn()
函数传回的错误类型。我在任何地方都找不到这方面的文档。现在我只是在猜测它会返回什么。我想要的是告诉用户如何从错误中恢复。用户名是否不存在,密码是否不正确,格式是否错误等。阅读源代码给我的印象是 AmplifyException.recoveryMessage 是我想要的,但这仍然是有问题的,因为它不允许我自定义消息。
/**
* Sign in the user to the back-end service and set the currentUser for this application
* @param username User's username
* @param password User's password
*/
override fun initiateSignin(username : String, password : String) {
//Sign in the user to the AWS back-end
Amplify.Auth.signIn(
username,
password,
{result ->
if (result.isSignInComplete) {
Timber.tag(TAG).i("Sign in successful.")
//Load the user if the sign in was successful
loadUser()
} else {
Timber.tag(TAG).i("Sign in unsuccessful.")
//TODO: I think this will happen if the password is incorrect?
}
},
{error ->
Timber.tag(UserLogin.TAG).e(error.toString())
authenticationRecoveryMessage.value = error.recoverySuggestion
}
)
}
身份验证恢复消息是LiveData
我想更新一个快餐栏,它会告诉用户他们需要做什么才能成功登录。我觉得一定有某种方法可以从中得到我还没有弄清楚的错误。处理给用户的消息的理想方式是使用 XML 字符串进行翻译,所以我真的很想在小吃栏中使用我自己的字符串,但我需要知道注册时可能出错的事情以及正在传达的内容我通过error -> {}
回调。