Skip to content

Skip default logging for client errors#7229

Open
raashish1601 wants to merge 1 commit into
expressjs:masterfrom
raashish1601:codex/skip-client-error-logging
Open

Skip default logging for client errors#7229
raashish1601 wants to merge 1 commit into
expressjs:masterfrom
raashish1601:codex/skip-client-error-logging

Conversation

@raashish1601
Copy link
Copy Markdown

Summary

Avoid logging errors from the default final handler when the resolved response status is a client error (4xx). Server errors continue to be logged in non-test environments.

Why

Express currently logs any error object that reaches the default final handler. For expected client errors such as 404 or 400, this adds noisy console.error output even though the response is already a client-error response.

Fixes #2263.

Testing

  • npx mocha --require test/support/env --reporter spec --check-leaks test/app.js
  • npx eslint lib/application.js test/app.js
  • npm test
  • npm run lint

@raashish1601 raashish1601 marked this pull request as ready for review May 11, 2026 10:22
Copy link
Copy Markdown
Contributor

@krzysdz krzysdz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As stated in #2263 (comment), Express should not duplicate the logic from finalhandler and instead the status determined by finalhandler should be passed to the error handler to decide whether a message should be logged.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Default responder should not console.error 4xx errors

2 participants