简体   繁体   English

预期在箭头函数的末尾返回一个值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.',
      });
    });
};

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() 的thencatch箭头函数中,如下所示:

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.

相关问题 预期在箭头函数的结尾处返回一个值。 (一致返回) - Expected to return a value at the end of arrow function. (consistent-return) Firebase云功能警告:“箭头功能预期没有返回值一致 - 返回” - Firebase Cloud Functions warning: “Arrow function expected no return value consistent-return” 使用简单箭头 function 修复“一致返回”linter 问题 - Fixing 'consistent-return' linter issue with simple arrow function JavaScript,预期在箭头函数的末尾返回一个值 - JavaScript, Expected to return a value at the end of arrow function 错误预期在箭头函数的末尾返回一个值 - Error Expected to return a value at the end of arrow function 预期在箭头函数错误的末尾返回一个值 - Expected to return a value at the end of arrow function error 预期在react中的箭头函数末尾返回一个值 - Expected to return a value at the end of arrow function in react 重构:期望在箭头函数的末尾返回一个值 - Refactor: Expected to return a value at the end of arrow function 预计在箭头 function 的末尾使用 if 语句返回一个值 - Expected to return a value at the end of arrow function with if statement 预期在箭头函数结束时返回一个值:array-callback-return - Expected to return a value at the end of arrow function: array-callback-return
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM