Handle duplicate value error in CRUD app (react-redux + express-mongoose) Handle duplicate value error in CRUD app (react-redux + express-mongoose) mongoose mongoose

Handle duplicate value error in CRUD app (react-redux + express-mongoose)


As mentioned in comments, I think you have .then() on your json() instead of on your fetch(). You need something of the shape:

export const addNewCar = car => {  console.log(car);  return dispatch => {    dispatch(addNewCarRequest(car));    return fetch(apiUrl, {      method: "post",      body: car    })      .then(response => {        if (response.ok) {          return response.json();        } else {          throw Error('blah')        }      })      .then(data => {        console.log(data.car);        dispatch(addNewCarRequestSuccess(data.car, data.message));      })      .catch(error => {        dispatch(addNewCarRequestFailed(error));              });  };};