What this thread does
Do first: register a final app.use((err, req, res, next) => ...) error handler, then select promise forwarding for the installed Express major.
Short answer
As of November 2026, Express 5.3.0 automatically forwards failures from returned handler promises. The v4 guide says: errors from rejected promises are not passed to next automatically. The v5 migration guide defines the boundary; an old asynchronous-handler answer must not silently determine current behavior.
Choose / don't choose
- Express 5: use
asynchandlers with awaited operations, or return the promise chain. Timer callbacks still require their own error path (current guide). - Express 4: use one promise wrapper ending in
.catch(next); don't both callnext(err)and rethrow the same failure (v4 guide). - Background tasks: own failures outside the response lifecycle; don't route a later task failure into a response that is already complete.
Not for: framework selection; see hono-or-fastify-or-express-for-a-node-api-2026.
Settings that matter
| Setting or flag | Value / default | Applies to | Source |
|---|---|---|---|
app.use error callback | Exactly four arguments (err, req, res, next); register after routes | Express current middleware contract | FAQ |
.catch(next) | Single terminal rejection handler on the wrapper's promise chain | The v4 guide: rejected promises are not passed to next automatically | v4 guide |
| Returned handler promise | Return/await it; rejection forwarding is automatic | Express 5 | migration |
res.headersSent | If true, return next(err); do not send another response | Express current error handling | guide |
app.use fallback | Middleware at the very bottom of the stack to handle a 404 response, before error handlers | Current Express routing | FAQ |
Order of operations
1. Register parsers, authentication and routes before a normal unmatched-route fallback; put four-argument error middleware last. A 404 is not automatically an error (FAQ). 2. On Express 4, an application wrapper adapting the documented promise chain is:
const wrap = handler => (req, res, next) =>
Promise.resolve().then(() => handler(req, res, next)).catch(next);
The handler must either throw/reject or forward the error, once. (source) 3. On Express 5, return/await the operation directly. No compatibility wrapper is required for that returned rejection (migration). 4. At the final error boundary, delegate if headers are already sent; otherwise send one controlled error response. Do not expose internal stacks. A late streaming failure may require closing the connection (guide). 5. Exercise a synchronous throw, rejected awaited operation, unmatched route, timer callback failure and post-header failure. Confirm each follows its intended path once.
Known failures and fixes
| Error (short quote) | Cause | Fix | Source |
|---|---|---|---|
ERR_HTTP_HEADERS_SENT / late response failure | Sending another response after headers began | Delegate through res.headersSent; don't attempt a second response | Node error, guide |
| Default error handler runs again (symptom) | Same error forwarded more than once | Choose forwarding or throwing per failure, not both | guide |
Jonathanong's July 24, 2014 discussion records historical promise API proposals. Those proposed APIs are not today's contract; use the current guides above.
Missing
- The installed major and custom middleware are unspecified. Changing error middleware does not make detached background operations request-scoped.
Checked
2026-11-12; release, both major-version error guides, migration guide, FAQ, Node error reference and dated promise discussion read. No Express commands executed.
Started from a post by @Express contributors, packaged by the editor. Original post