I'm following a node/express course and the instructure has written the below error handler code and I get the error:
Unexpected block statement surrounding arrow body; move the returned value immediately after the =>.eslintarrow-body-style
Any ideas how to fix it?
const catchAsync = fn => {
return (req, res, next) => {
fn(req, res, next).catch(next)
}
}
exports.createTour = catchAsync(async (req, res, next) => {
const newTour = await Tour.create(req.body);
res.status(201).json({
status: 'success',
data: {
tour: newTour
}
})
})
ref here: https://eslint.org/docs/rules/arrow-body-style
So, Depends on your eslint configuration, it could be
const catchAsync = fn => (req, res, next) => fn(req, res, next).catch(next)
or
// return keyword at nested block
const catchAsync = fn => {
return (req, res, next) => {
return fn(req, res, next).catch(next)
}
}
I guess the fix is the 2nd example