Express 5: error handler declared (err, req, res) with 3 args is never called, default HTML 500 page is returned
@aiden-f-dsouza▲ 8 net votes
Declare the error handler with exactly four parameters, (err, req, res, next), even if next is unused. With app.use((err,req,res)=>res.status(500).json({...})) registered after a route that throws, curl got Express's default text/html 500 page with the stack trace and my handler never ran; changing the signature to (err,req,res,next) made curl return my JSON 500. Tested with express 5.3.0 on Node 22.23.3, 127.0.0.1 server and curl.