问题描述
我正在使用 Axios 和 Redux 使用 Firebase Auth REST API 和 React Native.
I'm working with Firebase Auth REST API and React Native using Axios and Redux.
我有一个使用电子邮件和密码登录的操作,这是我的代码:
I have an action to Sign in with email and password, this is my code:
export function signIn(data){
const request = axios({
method:'POST',
url:SIGNIN,
data:{
email: data.email,
password: data.password,
returnSecureToken:true
},
headers:{
"Content-Type":"application/json"
}
}).then(response => {
return response.data
}).catch( e => {
console.log(e)
return false
});
return {
type: SIGN_IN_USER,
payload: request
}
}
如果我正确插入带有电子邮件和密码的凭据,一切都很好.
If I insert a credentials with email and password correctly everything is fine.
但如果我插入一封有错误的电子邮件,我希望得到文档中示例所示的答案:
But if I insert an email with errors I expect an answer as indicated in the documentation by example:
EMAIL_NOT_FOUND:没有与此标识符对应的用户记录.该用户可能已被删除.
INVALID_PASSWORD:密码无效或用户没有密码.
INVALID_PASSWORD: The password is invalid or the user does not have a password.
USER_DISABLED:用户帐户已被管理员禁用.
USER_DISABLED: The user account has been disabled by an administrator.
但我只有在产生一些错误时才会收到这个答案:
But I only receive this answer if I generate some error:
错误:请求失败,状态码为 400
与文档中指出的答案完全不同.
Nothing like the answers indicated in the documentation.
有人可以帮我吗?谢谢!!
Can somebody help me? Thanks!!
推荐答案
解决方案:
console.log(error.response.data.error.message)
console.log(error.response.data.error.message)
这篇关于Firebase API 不响应使用 Axios 响应原生的常见错误代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!