[英]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.