简体   繁体   English

错误预期在箭头函数的末尾返回一个值

[英]Error Expected to return a value at the end of arrow function

const jwt = require('jsonwebtoken');

module.exports = (req, res, next) => {
  try {
    const token = req.headers.authorization;
    const decoded = jwt.verify(token, 'somes');
    req.user = decoded.user;
    next();
  } catch (error) {
    return res.status(401).json({
      message: 'Auth failed',
    });
  }
};

This is my check-auth middle ware I've configured AirBnB coding standards for this expressjs project.这是我的check-auth中间件,我为这个 expressjs 项目配置了 AirBnB 编码标准。

I got an linting error.我有一个 linting 错误。 What does this really mean and how can I get rid of this error?这到底是什么意思,我怎样才能摆脱这个错误? Is it okay to put return statement in front of the next() function call like this return next();像这样return next();在 next() 函数调用之前放置 return 语句可以吗return next(); How does that affect to the code?这对代码有何影响?

error Expected to return a value at the end of arrow function consistent-return错误预期在箭头函数的末尾返回一个值consistent-return

It's complaining that one of your code paths is returning a value, but the other isn't.它抱怨您的一个代码路径正在返回一个值,但另一个没有。 Returning a value isn't necessary here.这里不需要返回值。

Change改变

return res.status(401).json({
  message: 'Auth failed',
});

to

res.status(401).json({
  message: 'Auth failed',
});

In my case I had my function that is inside the hook useSelector and I was using it together with the keys就我而言,我的函数位于钩子 useSelector 内,并且我将它与键一起使用

   const petitions = useSelector((store) => {store.cachePetitions.results});

My solution only remove the keys and thus the error generated by eslint disappeared我的解决方案只删除了密钥,因此 eslint 产生的错误消失了

const petitions = useSelector((store) => store.cachePetitions.results);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 预期在箭头函数错误的末尾返回一个值 - Expected to return a value at the end of arrow function error 预期在 reactjs 上的箭头函数末尾返回一个值如何修复此错误? - Expected to return a value at the end of arrow function on reactjs how to fix this error? React JSX 错误预期在箭头 function 末尾有一个返回值 - React JSX error expected a return value at the end of the arrow function 期望在箭头 function 错误的末尾返回一个值 - Getting expected to return a value at the end of the 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 JavaScript,预期在箭头函数的末尾返回一个值 - JavaScript, 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 预期在箭头函数结束时返回一个值:array-callback-return - Expected to return a value at the end of arrow function: array-callback-return
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM