我有一个react应用程序,它通过Node和express发出一个简单的发布请求。数据到达正确的端点,正确存储,并返回状态为(200)的数据。一切正常,但是在try catch块内发出的请求始终会调度类型:ERROR来自catch块。
这是从快递端开始的
try {
const newQuestion = new Question({
question,
difficulty,
correctAnswer,
wrongAnswerOne,
wrongAnswerTwo,
wrongAnswerThree,
submittedBy: {
name,
email,
organization
}
});
const addQuestion = await newQuestion.save();
console.log(addQuestion);
res.json(addQuestion);
} catch (error) {
console.error(error.message);
res.status(500).send("Error at question POST");
}
这来自客户端React。
try {
const res = await axios.post("/questions", question, config);
console.log("res", res);
dispatch({
type: ADD_QUESTION,
payload: res.data
});
} catch (err) {
dispatch({
type: QUESTION_ERROR,
payload: err.data
});
}
};
感谢您的帮助!