gpt4 book ai didi

javascript - 堆栈跟踪错误仍然显示在我的控制台上

转载 作者:行者123 更新时间:2023-11-30 06:13:31 26 4
gpt4 key购买 nike

我正在尝试通过 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);

不太确定如何处理堆栈跟踪错误

image of error这是我的控制台的图片

最佳答案

我认为 await 关键字可能会导致此错误。 try..catch 无法捕获 await 语句中的错误。

关于javascript - 堆栈跟踪错误仍然显示在我的控制台上,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57446529/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com