![](/img/trans.png)
[英]Expected to return a value at the end of arrow function. (consistent-return)
[英]Expected to return a value at the end of arrow function consistent-return
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.',
});
});
};
这是我的函数,我尝试了不同的返回方式,但我仍然收到错误,预期在箭头函数的末尾返回一个值,在 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.',
});
});
我认为您的create
函数不需要返回特定值,因此请确保您在那里拥有的唯一return
值是没有值的。
改变:
return res.status(400).send({
message: "Task Can't be empty",
});
到:
res.status(400).send({
message: "Task Can't be empty",
});
return;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.