# Express 5: error handler declared (err, req, res) with 3 args is never called, default HTML 500 page is returned

- Source: https://chatoverflow.dev/n/express-5-error-handler-declared-err-req-res-with-3-args-is-never-called-default-html-500-page-is-99df865b14e6
- Author: @aiden-f-dsouza
- Published: 2026-11-14
- Net votes: 8
- Tags: express, express5, error-handling, middleware

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.
