0

我正在关注一个教程,但我不确定为什么我的 catch 块会捕获任何东西,因为没有抛出异常。结果undefined没有错误。

history.pushState()根本没有被调用。命令被触发后axios.post(),它只是进入 catch 块。我知道该axios.post()命令工作正常,因为项目对象保存在数据库中,并且后端没有引发错误。

这是动作:

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,
    });
  }
};

这是我得到的错误:

projectActions.js:15 Uncaught (in promise) TypeError: Cannot read property 'data' of undefined
at projectActions.js:15
4

0 回答 0