This plugin for Fastify integrates `http-errors-enhanced` to provide comprehensive and customizable error handling for web applications. It allows developers to configure how 404 errors are handled, whether unhandled server errors expose stack traces in production, and how validation errors (both request and response) are structured. The current stable version is 7.0.1. Releases appear to follow major version bumps for Node.js compatibility changes and minor/patch releases for bug fixes and dependency updates, indicating an active and well-maintained project with a steady, predictable cadence. A key differentiator is its ability to convert validation errors into a structured, human-readable format and its extensibility for modifying error processing or customizing AJV instances for response validation. It provides a consistent error response format compatible with standard Fastify errors, capable of including custom properties and headers derived from the enhanced error objects.
npm install fastify-http-errors-enhancedVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to register the `fastify-http-errors-enhanced` plugin, configure its options, and throw an enhanced `NotFoundError` within a route handler to see the custom error response format and headers in action. It also shows a basic working route.
Upgrade your Node.js environment to version 22.21.0 or higher, or use a previous major version of `fastify-http-errors-enhanced` that supports your Node.js version.
Upgrade your Node.js environment to version 20 or higher, or pin `fastify-http-errors-enhanced` to a version like `^5.0.0` if you need Node.js 18 compatibility.
Always use `await server.register(fastifyHttpErrorsEnhanced)` when setting up your Fastify instance, or encapsulate routes that rely on this plugin within a `fastify-plugin` block.
Explicitly set `hideUnhandledErrors: true/false` and `convertResponsesValidationErrors: true/false` in the plugin options when registering to ensure consistent behavior across environments regardless of `NODE_ENV`.
Upgrade your Node.js environment to at least version 22.21.0, or downgrade `fastify-http-errors-enhanced` to a major version compatible with your current Node.js version.
Ensure `fastify-http-errors-enhanced` is registered early in your Fastify application setup, preferably before any routes are defined, and use `await server.register(...)` to ensure proper asynchronous registration.