Core Development Concepts > Extending and Customizing
Customizing the Error Output
Learn how to set a custom error handler to modify the error output
- how to set a custom error handler
- how to modify the error output
Introduction
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
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
Example: Create a Custom Handler via Function
Registering the Plugin
In both cases of creating the Fastify modifier plugin, users need to register the plugin the same location.
Users MUST register the plugin in both GraphQL (apps/api/graphql/src/index.ts
) and HeadlessCMS (apps/api/headlessCMS/src/index.ts
) Lambda handlers.