exports.create = (req, res) => {
if (!req.body.task) {
return res.status(400).send({
message: "Task Can't be empty",
});
}
const task = new Task({
task: req.body.task,
});
task.save()
.then((data) => {
res.send(data);
})
.catch((err) => {
res.status(500).send({
message: err.message || 'Some error occurred while creating the Task.',
});
});
};
这是我的函数,我尝试了不同的返回方式,但仍然收到错误:
Expected to return a value at the end of arrow function consistent-return on 1:29.
谁能帮我解决这个问题吗?
最佳答案
将 return
添加到您的 task.save() 的 then
和 catch
箭头函数,如下所示:
task.save().then((data) => {
return res.send(data);
})
.catch((err) => {
return res.status(500).send({
message: err.message || 'Some error occurred while creating the Task.',
});
});
关于javascript - 期望在箭头函数的末尾返回一个值constraint-return,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59821663/