![](/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.