期望return箭头函数末尾的值一致-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.',
});
});
};
这是我的函数,我尝试了不同的方式来放置 return 但 O 仍然得到错误:
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.',
});
});
我认为您的 create
函数不需要 return 特定值,因此请确保您拥有的唯一 return
没有值。
变化:
return res.status(400).send({
message: "Task Can't be empty",
});
至:
res.status(400).send({
message: "Task Can't be empty",
});
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.',
});
});
};
这是我的函数,我尝试了不同的方式来放置 return 但 O 仍然得到错误:
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.',
});
});
我认为您的 create
函数不需要 return 特定值,因此请确保您拥有的唯一 return
没有值。
变化:
return res.status(400).send({
message: "Task Can't be empty",
});
至:
res.status(400).send({
message: "Task Can't be empty",
});
return;