Redux:未处理的拒绝(TypeError):无法读取未定义的属性“ data”

时间:2020-11-03 18:10:52

标签: javascript reactjs redux react-redux redux-thunk

在下面的我的redux操作文件中,出现以下错误-未处理的拒绝(TypeError):无法读取未定义的属性'data'。错误指向代码所在的行:dispatch(returnErrors(err.response.data,err.response.status,'LOGIN_FAIL'));

//动作文件登录用户

export const login = ({email, password, history}) => dispatch => {
    const config = {
        headers: {
            'Content-Type': 'application/json',
        },
    };

    const body = JSON.stringify({email, password});

    axios
        .post('/api/user/login/', body, config)
        .then(res => {
            dispatch({
                type: LOGIN_SUCCESS,
                payload: res.data,
            });
            history.push('/userfeed');
        })
        .catch(err => {
            dispatch(returnErrors(err.response.data, err.response.status, 'LOGIN_FAIL'));
            dispatch({
                type: LOGIN_FAIL,
            });
        });
};
//Return errors
export const returnErrors = (message, status, id = null) =>{
  return{
    type: GET_ERRORS,
    payload: {message, status, id}
  };
};

0 个答案:

没有答案