[英]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.',
});
});
};
This is my function and i tried different ways of putting return but i still get the error Expected to return a value at the end of arrow function consistent-return on 1:29.这是我的函数,我尝试了不同的返回方式,但我仍然收到错误,预期在箭头函数的末尾返回一个值,在 1:29一致返回。
Can anyone help me fix this ?谁能帮我解决这个问题?
Add return
to your task.save()'s then
and catch
arrow functions too like this:将
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.',
});
});
I don't think your create
function needs to return a specific value, so make sure that the only return
you have in there, is without value.我认为您的
create
函数不需要返回特定值,因此请确保您在那里拥有的唯一return
值是没有值的。
Change:改变:
return res.status(400).send({
message: "Task Can't be empty",
});
to:到:
res.status(400).send({
message: "Task Can't be empty",
});
return;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.