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

标签 javascript reactjs firebase

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

相关文章:

javascript - jQuery 替换 Node+jade 组合中的 Span

javascript - parent() 不适用于事件元素

javascript - Material UI Autocomplete Chip 多线

firebase - 使用 Cloud Functions SSR + 托管在 Firebase 上进行数据驱动的缓存?

firebase - 在同一字段上存储多个查询

javascript - 单击切换回第一个选项

javascript - AngularJS:依赖管理

javascript - 如果选择所有值,则显示列表中的所有结果

reactjs - 如何防止 Gatsby 图像在每次重新加载时模糊 Logo ?

Android:WAITING firebase valueEventListener