Skip to content

fix: keep original error when a named transact route fails before preHandler - #238

Open
RaphaelFakhri wants to merge 1 commit into
fastify:mainfrom
RaphaelFakhri:fix/named-transact-early-error
Open

RaphaelFakhri wants to merge 1 commit into
fastify:mainfrom
RaphaelFakhri:fix/named-transact-early-error

Conversation

@RaphaelFakhri

Copy link
Copy Markdown

When the plugin is registered with name and a route uses pg: { transact: name }, an error raised before the preHandler hook (schema validation, an onRequest hook) leaves req.pg as null. The onError and onSend hooks then call extractRequestClient(), which reads req.pg[name] and throws Cannot read properties of null (reading '<name>'). That message replaces the original error in the response.

This change:

  • Returns null from extractRequestClient() when no request client was set, so onSend skips the commit and release, as it already does for transact: true.
  • Skips the ROLLBACK in onError when there is no client.
  • Adds a test for schema validation failure on a named transact route.

Fixes #237

Checklist

@mcollina mcollina left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

lgtm

This branch has not been deployed

No deployments
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.

Named transact route replaces the original error when the request fails before preHandler

2 participants