[英]Stack trace error is still showing up on my console
我正在嘗試通過 firebase 進行身份驗證注冊,一切正常。 但我正在嘗試對不正確/空字段做一些錯誤處理,我得到:
index.js:1509 Uncaught Error: The error you provided does not contain a stack trace.
我能夠從 firebase 檢索錯誤消息,然后將其置於錯誤狀態並將消息呈現在屏幕上,但堆棧跟蹤錯誤仍顯示在我的控制台上。
export const signUp = (newUser) => async (dispatch, getState, { getFirebase, getFirestore }) => {
try {
const firebase = getFirebase();
const firestore = getFirestore();
const response = await firebase.auth().createUserWithEmailAndPassword(
newUser.email,
newUser.password
);
firestore.collection('users').doc(response.user.uid).set({
firstName: newUser.firstName,
lastName: newUser.lastName,
initials: newUser.firstName[0] + newUser.lastName[0]
});
dispatch({
type: SIGN_UP_SUCCESS
});
} catch(err) {
dispatch({
type: SIGN_UP_ERR,
payload: err
});
console.log(err)
}
};
import React, { useRef } from 'react';
import { Redirect } from 'react-router-dom';
import { connect } from 'react-redux';
import { signUp } from '../../store/actions/authActions';
const SignUp = props => {
const emailRef = useRef();
const passwordRef = useRef();
const firstNameRef = useRef();
const lastNameRef = useRef();
const handleSubmit = (e) => {
e.preventDefault();
const newUser = {
email: emailRef.current.value,
password: passwordRef.current.value,
firstName: firstNameRef.current.value,
lastName: lastNameRef.current.value
};
props.signUp(newUser);
};
if(props.auth.uid) return <Redirect to='/' />
console.log('props: ', props)
return (
<div className="container">
<form onSubmit={(e) => handleSubmit(e)} className="white">
<h5 className="grey-text text-darken-3">Sign Up</h5>
<div className="input-field">
<label htmlFor="email">email</label>
<input type="email" id="email" ref={emailRef} />
</div>
<div className="input-field">
<label htmlFor="password">password</label>
<input type="password" id="password" ref={passwordRef} />
</div>
<div className="input-field">
<label htmlFor="firstName">first name</label>
<input type="text" id="firstName" ref={firstNameRef} />
</div>
<div className="input-field">
<label htmlFor="lastName">last name</label>
<input type="text" id="lastName" ref={lastNameRef} />
</div>
<div className="input-field">
<button className="button btn pink lighten-1 z-depth-0">Sign up</button>
<div className="red-text center">
{ props.authErr ? <p>{ props.authErr }</p> : null }
</div>
</div>
</form>
</div>
);
};
const mapStateToProps = state => {
console.log('auth err:', state.auth.authError)
return {
auth: state.firebase.auth,
authErr: state.auth.authError
}
};
export default connect(mapStateToProps, { signUp })(SignUp);
不太確定如何處理堆棧跟蹤錯誤
這里的錯誤圖像是我的控制台的圖像
我認為 await 關鍵字可能會導致此錯誤。 try..catch 無法捕獲 await 語句中的錯誤。
我認為這個錯誤是由 firebase 庫打印的,然后它返回錯誤(這是你在 catch 中收到的)。 我覺得奇怪的是,如果您使用“then, catch”,則不會出現該錯誤,它僅在使用 async await 時顯示。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.