handling error response from express to react handling error response from express to react mongoose mongoose

handling error response from express to react


So it turns out it wasn't my express response it was the fact that I needed to addconsole.log("CATCH = ", err.response); in my axios promise catch in react. I was missing the response object. I had no idea I need that.

For full code in case anyone else has the same issue.

React:

export function addCategoryName( name ){  return (dispatch) => {    const dbPost = axios.post('/api/add-category', {name:name});    dbPost.then(result => {      console.log("result = ", result);      dispatch({        type: type.ADD_CATEGORY_NAME,        payload: result.data      });    }).catch(err => {      console.log("CATCH = ", err.response);       dispatch({         type: type.ADD_CATEGORY_NAME_ERROR,         payload: error.response.data.error       });    });  }}