I'm trying to write an express middleware that handles errors. However, I'm not able to define a function with err as an argument. In the express documentation I read the following:
Define error-handling middleware functions in the same way as other middleware functions, except error-handling functions have four arguments instead of three: (err, req, res, next)
But when I define the following function, it seems like it's not invoked:
myFunction = (config) => {
return myFunction = (err, req, res, next) {
console.log(err)
}
}
module.exports = myFunction
The function above isn't invoked when I specify app.use(myFunction(config)) from my express server, but if I remove the err argument it is. Does anyone know why that is the case?