Skip to content

Question about async handlers that call reply.send() #548

@nwoltman

Description

@nwoltman

Why is the check implemented this way?

if (payload !== undefined || state.reply.res.statusCode === 204) {
  state.reply.send()
}

I would have expected it to be:

if (payload !== undefined || !state.reply.sent) {
  state.reply.send(payload)
}

I'm mainly concerned because I have a reply decorator that does this:

reply.code(204).send();

and if I use that inside an async handler, reply.send() gets called twice.

Plus I feel like it would be a better developer experience to send an empty response if the developer doesn't call reply.send() inside a handler that resolves to undefined rather than letting the request hang.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions