I am following a tutorial, but I am not sure why my catch block is catching anything as there is no exception thrown. The result is undefined
with no error.
The history.pushState()
doesn't get called at all. After the axios.post()
command is fired, it just goes to the catch block. I know the axios.post()
command is working properly because the project object is saved in the database and no error is thrown in the backend.
Here is the action:
import axios from "axios";
import { GET_ERRORS } from "./types";
export const createProject = (project, history) => async (dispatch) => {
try {
const res = await axios.post("http://localhost:8080/api/project", project);
history.pushState("/dashboard");
} catch (err) {
dispatch({
type: GET_ERRORS,
payload: err.response.data,
});
}
};
This the error I get:
projectActions.js:15 Uncaught (in promise) TypeError: Cannot read property 'data' of undefined
at projectActions.js:15