Skip to content

fix: deduplicate error logging via pino-http customProps (#299) - #361

Merged
David-patrick-chuks-02 merged 2 commits into
Lilly-Protocol:mainfrom
rafaio1:single-error-log-299
Sep 6, 2026
Merged

fix: deduplicate error logging via pino-http customProps (#299)#361
David-patrick-chuks-02 merged 2 commits into
Lilly-Protocol:mainfrom
rafaio1:single-error-log-299

Conversation

@rafaio1

@rafaio1 rafaio1 commented Sep 4, 2026

Copy link
Copy Markdown
Contributor

Summary

Deduplicates error logging for failed requests by attaching error details to response.locals in the error middleware, allowing pino-http to log them once in its response line via customProps.

Changes

  • src/common/http/error.middleware.ts: Removed duplicate logger[logLevel](...) call. Instead, attaches structured error details (err, statusCode, code, details) to response.locals.errorDetails.
  • src/app.ts: Added customProps callback to pino-http config that reads response.locals.errorDetails and includes err in the single response log entry.

Result

Failed requests now produce exactly one log line (the pino-http response log) with full error context, instead of two separate log entries. All error fields (err, statusCode, code, details) are preserved.

Closes #299

…col#299)

Attach error details to response.locals in error middleware so pino-http
logs them once in its response line instead of emitting a separate error
log. This eliminates duplicate log entries for failed requests while
preserving all error context (err, statusCode, code, details).
@rafaio1

rafaio1 commented Sep 4, 2026

Copy link
Copy Markdown
Contributor Author

CI is failing due to two pre-existing lint errors in the base branch (not introduced by this PR):

  1. src/app.ts:88@typescript-eslint/no-explicit-any
  2. src/common/http/error.middleware.ts:5 — unused logger import

These exist on main and block all open PRs. Suggest fixing them directly on main or via a dedicated lint-fix PR so the CI gate passes for everyone.

This PR (#299) correctly deduplicates error logging via pino-http customProps and is ready for review once the lint gate clears.

@David-patrick-chuks-02
David-patrick-chuks-02 merged commit 7bcbef3 into Lilly-Protocol:main Sep 6, 2026
1 check failed
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.

[Bounty: $90] Emit a single error log line per failed request instead of duplicating pino-http and error-middleware output

3 participants