我从NodeJS开始。在error handling中,以下代码声明了next
回调并且不使用它:
app.get('/user/:id', async function (req, res, next) {
var user = await getUserById(req.params.id)
res.send(user)
})
因为next(value)
在Express 5中是隐式的:Starting with Express 5, route handlers and middleware that return a Promise will call next(value) automatically when they reject or throw an error.
此快捷方式与代码质量检查冲突。在脚本上运行ESLint时,我得到:
server/app.js
95:26 error 'next' is defined but never used no-unused-vars
获得相同功能并确保代码质量的适当方法是什么:从函数的参数中删除next
?在末尾添加next()
?还是禁用代码检查规则?
最佳答案
您没有使用next()。所以只要删除这个。
app.get('/user/:id', async function (req, res) {
var user = await getUserById(req.params.id);
res.send(user);`
})
关于node.js - Express错误处理中的代码质量检查与隐式next()之间的冲突,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65289495/