bradtraversy / mern_shopping_list

Shopping List built with MERN and Redux
605 stars 436 forks source link

I get error response even though registration is successful #26

Closed geekdaniels closed 5 years ago

geekdaniels commented 5 years ago

Hi Brad, I am facing an issue I get an err.response even though the user is registered to the database.

Here is my dispatch

export const register = ({ firstName, lastName, email, password, rePassword }) => dispatch => { // Headers const config = { headers: { "Content-type": "application/json" } };

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

axios .post(${process.env.REACT_APP_API_URL}/users/create, body, config) .then(res => dispatch({ type: REGISTER_SUCCESS, payload: res.data }) ) .catch(err => { dispatch( returnErrors( err.response.data, err.response.status, "REGISTER_FAIL" ) ) dispatch({ type: REGISTER_FAIL }); }); };

Error displayed!!!

Unhandled Rejection (TypeError): err.response is undefined

78 | }) 79 | ) 80 | .catch(err => {

81 | dispatch( | ^ 82 | returnErrors( 83 | err.response.data, 84 | err.response.status,