Skip to content

Interface: FastifyResponder ​

How fastifyHTTPEntrypoint writes the results and the errors of the actions (its respond option). Implement it to give the responses another shape; FastifyJSONResponder is the default, fastifyJSONEnvelope wraps them in an envelope. The file results and the event streams are not written by the responder.

Methods ​

error() ​

error(reply, error, request, origin?): void

Write an error: a failed action (validation, access control, its own exception), an error of fastify (a hook such as an authenticator, a body too large), or a request matching no route (RouteNotFoundException). Not called for an action once the reply is sent, nor after the client left.

Parameters ​

reply ​

FastifyReply

The fastify reply to send.

error ​

unknown

The thrown error.

request ​

FastifyRequest

The fastify request being answered.

origin? ​

HTTPErrorOrigin

Where the error comes from: 'action' (the dispatch of an action failed) or 'request' (a hook, an error of fastify, a route not found); see HTTPErrorOrigin.

Returns ​

void


success() ​

success(reply, data, request): void

Write the result of an action. For a StatusResult, its status and headers are already set on the reply and data is its payload.

Parameters ​

reply ​

FastifyReply

The fastify reply to send.

data ​

unknown

The action's result, undefined when it returned nothing.

request ​

FastifyRequest

The fastify request being answered.

Returns ​

void

Released under the MIT License.