Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: call preHandler on reply.callNotFound #2256

Merged
merged 3 commits into from
May 6, 2020

Conversation

salmanm
Copy link
Member

@salmanm salmanm commented May 5, 2020

Fixes #2229

Checklist

  • run npm run test and npm run benchmark
  • tests and/or benchmarks are included
  • documentation is changed or added
  • commit message and code follows Code of conduct

@salmanm salmanm force-pushed the hooks-not-found branch 2 times, most recently from 26035fc to 51cd64f Compare May 5, 2020 14:54
@salmanm salmanm force-pushed the hooks-not-found branch from 51cd64f to 14dda31 Compare May 5, 2020 14:57
@salmanm salmanm changed the base branch from 2.x to master May 5, 2020 14:57
@mcollina mcollina added the backport 2.x Issue or pr that should be backported to Fastify v2 label May 5, 2020
@delvedor delvedor added bugfix Issue or PR that should land as semver patch v3.x Issue or pr related to Fastify v3 labels May 5, 2020
Copy link
Member

@delvedor delvedor left a comment

Choose a reason for hiding this comment

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

Hello! Thank you for the pr.
I think we should reuse the preHandlerCallback present in lib/handleRequest.js

function preHandlerCallback (err, request, reply) {
if (reply.sent ||
reply.raw.writableEnded === true ||
(reply.raw.writable === false && reply.raw.finished === true)) return
if (err != null) {
reply.send(err)
return
}
var result
try {
result = reply.context.handler(request, reply)
} catch (err) {
reply.send(err)
return
}
if (result !== undefined) {
if (result !== null && typeof result.then === 'function') {
wrapThenable(result, reply)
} else {
reply.send(result)
}
}
}

As you can see we are also doing more work, namely the synchronous error checking.

Copy link
Member

@mcollina mcollina left a comment

Choose a reason for hiding this comment

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

lgtm

@salmanm salmanm changed the title Hooks not found Fix:call preHandler on reply.callNotFound May 5, 2020
@salmanm salmanm changed the title Fix:call preHandler on reply.callNotFound Fix: call preHandler on reply.callNotFound May 5, 2020
Copy link
Member

@delvedor delvedor left a comment

Choose a reason for hiding this comment

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

LGTM

@delvedor
Copy link
Member

delvedor commented May 6, 2020

I expect the automatic backport to fail since the preHandlerCallback code has been changed in v3.

@mcollina mcollina removed the backport 2.x Issue or pr that should be backported to Fastify v2 label May 6, 2020
@mcollina mcollina merged commit ae6b57c into fastify:master May 6, 2020
@mcollina mcollina added the backport 2.x Issue or pr that should be backported to Fastify v2 label May 6, 2020
frikille pushed a commit to frikille/fastify that referenced this pull request May 6, 2020
* fix: run preHandler in notFound

* doc: update docs for setNotFoundHandler

* fix: reuse preHandlerCallback
mcollina pushed a commit that referenced this pull request May 7, 2020
* fix: run preHandler in notFound

* doc: update docs for setNotFoundHandler

* fix: reuse preHandlerCallback

Co-authored-by: Salman Mitha <salmanmitha@gmail.com>
@github-actions
Copy link

This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 10, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
backport 2.x Issue or pr that should be backported to Fastify v2 bugfix Issue or PR that should land as semver patch v3.x Issue or pr related to Fastify v3
Projects
None yet
Development

Successfully merging this pull request may close these issues.

reply.callNotFound not triggering hooks
3 participants