What you'll learn
  • how to set a custom error handler
  • how to modify the error output

Introduction
anchor

In the 5.34.0 version we added a possibility for users to modify our Fastify handler instance, via the ModifyFastifyPlugin. To find our more on how and why we use Fastify, please read this article.

With the given plugin user can change and add anything to the Fastify instance, including the error handler.

We have our built-in error handler, but if it does not suit the user, they can change it.

Creating the Modifier Plugin to Set a Custom Error Handler
anchor

There is a plugin class, ModifyFastifyPlugin, which user can construct, or they can use a function which in turn constructs the plugin from the ModifyFastifyPlugin class.

Example: Create a Custom Handler via Class
anchor

Example: Create a Custom Handler via Function
anchor

Registering the Plugin
anchor

In both cases of creating the Fastify modifier plugin, users need to register the plugin the same location.

Users MUST register the plugin only in the GraphQL (apps/api/graphql/src/index.ts) Lambda handler.