Skip to content

fix: pass middleware errors to pino-http - #71

Open
yowainwright wants to merge 1 commit into
pinojs:masterfrom
yowainwright:fix/pass-middleware-errors-to-pino-http
Open

yowainwright wants to merge 1 commit into
pinojs:masterfrom
yowainwright:fix/pass-middleware-errors-to-pino-http

Conversation

@yowainwright

Copy link
Copy Markdown
Contributor

Description

This revives the small fix from #20 against the current codebase.

When downstream Koa middleware throws:

  1. koa-pino-logger currently logs the error immediately with ctx.log.error({ err }), then
  2. rethrows. pino-http also logs the request on response completion, which
  3. can produce duplicate request logs for the same failure.

This change stores the middleware error on ctx.res.err and rethrows it, letting pino-http include the error in its normal response-completion log.

Validation

  • npm test

Thank you!
~Jeff

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.

using ctx.throw results in both request errored and request completed being logged

1 participant