Skip to content

feat: preserve Express errors in automatic logs - #431

Open
drewmt wants to merge 1 commit into
pinojs:masterfrom
drewmt:feature/express-error-handler
Open

feat: preserve Express errors in automatic logs#431
drewmt wants to merge 1 commit into
pinojs:masterfrom
drewmt:feature/express-error-handler

Conversation

@drewmt

@drewmt drewmt commented Aug 20, 2026

Copy link
Copy Markdown

Summary

  • add an Express error middleware to preserve the original application error on the response
  • forward the same error to the remaining Express error handlers without registering duplicate log listeners
  • document the middleware ordering and cover the runtime and TypeScript contracts

Why

Express response completion events do not expose an error after the application error handler has processed it. This lets pino-http use the original error instead of synthesizing a generic status-code error for automatic logs.

Testing

  • npm test
  • 65 tests passed, 1 existing test skipped
  • 100% statement, branch, function, and line coverage for logger.js
  • TypeScript, tsd, and ts-node validation passed

Closes #348

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.

Pino-http logs a different error from the one sent by express

1 participant