Skip to content

possible misleading doc example in addHook about returning reply ? #5182

@kswope

Description

@kswope

Prerequisites

  • I have written a descriptive issue title
  • I have searched existing issues to ensure the issue has not already been raised

Issue

https://fastify.dev/docs/latest/Reference/Hooks/#respond-to-a-request-from-a-hook

This code here

fastify.addHook('onRequest', (request, reply, done) => {
  reply.send('Early response')
})

// Works with async functions too
fastify.addHook('preHandler', async (request, reply) => {
  await something()
  reply.send({ hello: 'world' })
  return reply // mandatory, so the request is not executed further
})

The above docs imply that both hooks will run and returning reply is mandatory to stop processing, but in my experiments I found this to not be true.

There is also this issue that seems to back me up

#677

Metadata

Metadata

Assignees

No one assigned

    Labels

    documentationImprovements or additions to documentationgood first issueGood for newcomers

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions