strong-tie/inbound-calls
0
1<h1 align="center">Fastify</h1>2 3## Errors4<a id="errors"></a>5 6**Table of contents**7- [Errors](#errors)8 - [Error Handling In Node.js](#error-handling-in-nodejs)9 - [Uncaught Errors](#uncaught-errors)10 - [Catching Errors In Promises](#catching-errors-in-promises)11 - [Errors In Fastify](#errors-in-fastify)12 - [Errors In Input Data](#errors-in-input-data)13 - [Catching Uncaught Errors In Fastify](#catching-uncaught-errors-in-fastify)14 - [Errors In Fastify Lifecycle Hooks And A Custom Error Handler](#errors-in-fastify-lifecycle-hooks-and-a-custom-error-handler)15 - [Fastify Error Codes](#fastify-error-codes)16 - [FST_ERR_NOT_FOUND](#fst_err_not_found)17 - [FST_ERR_OPTIONS_NOT_OBJ](#fst_err_options_not_obj)18 - [FST_ERR_QSP_NOT_FN](#fst_err_qsp_not_fn)19 - [FST_ERR_SCHEMA_CONTROLLER_BUCKET_OPT_NOT_FN](#fst_err_schema_controller_bucket_opt_not_fn)20 - [FST_ERR_SCHEMA_ERROR_FORMATTER_NOT_FN](#fst_err_schema_error_formatter_not_fn)21 - [FST_ERR_AJV_CUSTOM_OPTIONS_OPT_NOT_OBJ](#fst_err_ajv_custom_options_opt_not_obj)22 - [FST_ERR_AJV_CUSTOM_OPTIONS_OPT_NOT_ARR](#fst_err_ajv_custom_options_opt_not_arr)23 - [FST_ERR_CTP_ALREADY_PRESENT](#fst_err_ctp_already_present)24 - [FST_ERR_CTP_INVALID_TYPE](#fst_err_ctp_invalid_type)25 - [FST_ERR_CTP_EMPTY_TYPE](#fst_err_ctp_empty_type)26 - [FST_ERR_CTP_INVALID_HANDLER](#fst_err_ctp_invalid_handler)27 - [FST_ERR_CTP_INVALID_PARSE_TYPE](#fst_err_ctp_invalid_parse_type)28 - [FST_ERR_CTP_BODY_TOO_LARGE](#fst_err_ctp_body_too_large)29 - [FST_ERR_CTP_INVALID_MEDIA_TYPE](#fst_err_ctp_invalid_media_type)30 - [FST_ERR_CTP_INVALID_CONTENT_LENGTH](#fst_err_ctp_invalid_content_length)31 - [FST_ERR_CTP_EMPTY_JSON_BODY](#fst_err_ctp_empty_json_body)32 - [FST_ERR_CTP_INSTANCE_ALREADY_STARTED](#fst_err_ctp_instance_already_started)33 - [FST_ERR_INSTANCE_ALREADY_LISTENING](#fst_err_instance_already_listening)34 - [FST_ERR_DEC_ALREADY_PRESENT](#fst_err_dec_already_present)35 - [FST_ERR_DEC_DEPENDENCY_INVALID_TYPE](#fst_err_dec_dependency_invalid_type)36 - [FST_ERR_DEC_MISSING_DEPENDENCY](#fst_err_dec_missing_dependency)37 - [FST_ERR_DEC_AFTER_START](#fst_err_dec_after_start)38 - [FST_ERR_DEC_REFERENCE_TYPE](#fst_err_dec_reference_type)39 - [FST_ERR_HOOK_INVALID_TYPE](#fst_err_hook_invalid_type)40 - [FST_ERR_HOOK_INVALID_HANDLER](#fst_err_hook_invalid_handler)41 - [FST_ERR_HOOK_INVALID_ASYNC_HANDLER](#fst_err_hook_invalid_async_handler)42 - [FST_ERR_HOOK_NOT_SUPPORTED](#fst_err_hook_not_supported)43 - [FST_ERR_MISSING_MIDDLEWARE](#fst_err_missing_middleware)44 - [FST_ERR_HOOK_TIMEOUT](#fst_err_hook_timeout)45 - [FST_ERR_LOG_INVALID_DESTINATION](#fst_err_log_invalid_destination)46 - [FST_ERR_LOG_INVALID_LOGGER](#fst_err_log_invalid_logger)47 - [FST_ERR_LOG_INVALID_LOGGER_INSTANCE](#fst_err_log_invalid_logger_instance)48 - [FST_ERR_LOG_INVALID_LOGGER_CONFIG](#fst_err_log_invalid_logger_config)49 - [FST_ERR_LOG_LOGGER_AND_LOGGER_INSTANCE_PROVIDED](#fst_err_log_logger_and_logger_instance_provided)50 - [FST_ERR_REP_INVALID_PAYLOAD_TYPE](#fst_err_rep_invalid_payload_type)51 - [FST_ERR_REP_RESPONSE_BODY_CONSUMED](#fst_err_rep_response_body_consumed)52 - [FST_ERR_REP_READABLE_STREAM_LOCKED](#fst_err_rep_readable_stream_locked)53 - [FST_ERR_REP_ALREADY_SENT](#fst_err_rep_already_sent)54 - [FST_ERR_REP_SENT_VALUE](#fst_err_rep_sent_value)55 - [FST_ERR_SEND_INSIDE_ONERR](#fst_err_send_inside_onerr)56 - [FST_ERR_SEND_UNDEFINED_ERR](#fst_err_send_undefined_err)57 - [FST_ERR_BAD_STATUS_CODE](#fst_err_bad_status_code)58 - [FST_ERR_BAD_TRAILER_NAME](#fst_err_bad_trailer_name)59 - [FST_ERR_BAD_TRAILER_VALUE](#fst_err_bad_trailer_value)60 - [FST_ERR_FAILED_ERROR_SERIALIZATION](#fst_err_failed_error_serialization)61 - [FST_ERR_MISSING_SERIALIZATION_FN](#fst_err_missing_serialization_fn)62 - [FST_ERR_MISSING_CONTENTTYPE_SERIALIZATION_FN](#fst_err_missing_contenttype_serialization_fn)63 - [FST_ERR_REQ_INVALID_VALIDATION_INVOCATION](#fst_err_req_invalid_validation_invocation)64 - [FST_ERR_SCH_MISSING_ID](#fst_err_sch_missing_id)65 - [FST_ERR_SCH_ALREADY_PRESENT](#fst_err_sch_already_present)66 - [FST_ERR_SCH_CONTENT_MISSING_SCHEMA](#fst_err_sch_content_missing_schema)67 - [FST_ERR_SCH_DUPLICATE](#fst_err_sch_duplicate)68 - [FST_ERR_SCH_VALIDATION_BUILD](#fst_err_sch_validation_build)69 - [FST_ERR_SCH_SERIALIZATION_BUILD](#fst_err_sch_serialization_build)70 - [FST_ERR_SCH_RESPONSE_SCHEMA_NOT_NESTED_2XX](#fst_err_sch_response_schema_not_nested_2xx)71 - [FST_ERR_HTTP2_INVALID_VERSION](#fst_err_http2_invalid_version)72 - [FST_ERR_INIT_OPTS_INVALID](#fst_err_init_opts_invalid)73 - [FST_ERR_FORCE_CLOSE_CONNECTIONS_IDLE_NOT_AVAILABLE](#fst_err_force_close_connections_idle_not_available)74 - [FST_ERR_DUPLICATED_ROUTE](#fst_err_duplicated_route)75 - [FST_ERR_BAD_URL](#fst_err_bad_url)76 - [FST_ERR_ASYNC_CONSTRAINT](#fst_err_async_constraint)77 - [FST_ERR_INVALID_URL](#fst_err_invalid_url)78 - [FST_ERR_ROUTE_OPTIONS_NOT_OBJ](#fst_err_route_options_not_obj)79 - [FST_ERR_ROUTE_DUPLICATED_HANDLER](#fst_err_route_duplicated_handler)80 - [FST_ERR_ROUTE_HANDLER_NOT_FN](#fst_err_route_handler_not_fn)81 - [FST_ERR_ROUTE_MISSING_HANDLER](#fst_err_route_missing_handler)82 - [FST_ERR_ROUTE_METHOD_INVALID](#fst_err_route_method_invalid)83 - [FST_ERR_ROUTE_METHOD_NOT_SUPPORTED](#fst_err_route_method_not_supported)84 - [FST_ERR_ROUTE_BODY_VALIDATION_SCHEMA_NOT_SUPPORTED](#fst_err_route_body_validation_schema_not_supported)85 - [FST_ERR_ROUTE_BODY_LIMIT_OPTION_NOT_INT](#fst_err_route_body_limit_option_not_int)86 - [FST_ERR_ROUTE_REWRITE_NOT_STR](#fst_err_route_rewrite_not_str)87 - [FST_ERR_REOPENED_CLOSE_SERVER](#fst_err_reopened_close_server)88 - [FST_ERR_REOPENED_SERVER](#fst_err_reopened_server)89 - [FST_ERR_PLUGIN_VERSION_MISMATCH](#fst_err_plugin_version_mismatch)90 - [FST_ERR_PLUGIN_CALLBACK_NOT_FN](#fst_err_plugin_callback_not_fn)91 - [FST_ERR_PLUGIN_NOT_VALID](#fst_err_plugin_not_valid)92 - [FST_ERR_ROOT_PLG_BOOTED](#fst_err_root_plg_booted)93 - [FST_ERR_PARENT_PLUGIN_BOOTED](#fst_err_parent_plugin_booted)94 - [FST_ERR_PLUGIN_TIMEOUT](#fst_err_plugin_timeout)95 - [FST_ERR_PLUGIN_NOT_PRESENT_IN_INSTANCE](#fst_err_plugin_not_present_in_instance)96 - [FST_ERR_PLUGIN_INVALID_ASYNC_HANDLER](#fst_err_plugin_invalid_async_handler)97 - [FST_ERR_VALIDATION](#fst_err_validation)98 - [FST_ERR_LISTEN_OPTIONS_INVALID](#fst_err_listen_options_invalid)99 - [FST_ERR_ERROR_HANDLER_NOT_FN](#fst_err_error_handler_not_fn)100 101### Error Handling In Node.js102<a id="error-handling"></a>103 104#### Uncaught Errors105In Node.js, uncaught errors are likely to cause memory leaks, file descriptor106leaks, and other major production issues.107[Domains](https://nodejs.org/en/docs/guides/domain-postmortem/) were a failed108attempt to fix this.109 110Given that it is not possible to process all uncaught errors sensibly, the best111way to deal with them is to112[crash](https://nodejs.org/api/process.html#process_warning_using_uncaughtexception_correctly).113 114#### Catching Errors In Promises115If you are using promises, you should attach a `.catch()` handler synchronously.116 117### Errors In Fastify118Fastify follows an all-or-nothing approach and aims to be lean and optimal as119much as possible. The developer is responsible for making sure that the errors120are handled properly.121 122#### Errors In Input Data123Most errors are a result of unexpected input data, so we recommend [validating124your input data against a JSON schema](./Validation-and-Serialization.md).125 126#### Catching Uncaught Errors In Fastify127Fastify tries to catch as many uncaught errors as it can without hindering128performance. This includes:129 1301. synchronous routes, e.g. `app.get('/', () => { throw new Error('kaboom') })`1312. `async` routes, e.g. `app.get('/', async () => { throw new Error('kaboom')132 })`133 134The error in both cases will be caught safely and routed to Fastify's default135error handler for a generic `500 Internal Server Error` response.136 137To customize this behavior you should use138[`setErrorHandler`](./Server.md#seterrorhandler).139 140### Errors In Fastify Lifecycle Hooks And A Custom Error Handler141 142From the [Hooks documentation](./Hooks.md#manage-errors-from-a-hook):143> If you get an error during the execution of your hook, just pass it to144> `done()` and Fastify will automatically close the request and send the145> appropriate error code to the user.146 147When a custom error handler has been defined through148[`setErrorHandler`](./Server.md#seterrorhandler), the custom error handler will149receive the error passed to the `done()` callback (or through other supported150automatic error handling mechanisms). If `setErrorHandler` has been used151multiple times to define multiple handlers, the error will be routed to the most152precedent handler defined within the error [encapsulation153context](./Encapsulation.md). Error handlers are fully encapsulated, so a154`setErrorHandler` call within a plugin will limit the error handler to that155plugin's context.156 157The root error handler is Fastify's generic error handler. This error handler158will use the headers and status code in the `Error` object, if they exist. The159headers and status code will not be automatically set if a custom error handler160is provided.161 162Some things to consider in your custom error handler:163 164- you can `reply.send(data)`, which will behave as it would in [regular route165 handlers](./Reply.md#senddata)166 - objects are serialized, triggering the `preSerialization` lifecycle hook if167 you have one defined168 - strings, buffers, and streams are sent to the client, with appropriate169 headers (no serialization)170 171- You can throw a new error in your custom error handler - errors (new error or172 the received error parameter re-thrown) - will call the parent `errorHandler`.173 - `onError` hook will be triggered once only for the first error being thrown.174 - an error will not be triggered twice from a lifecycle hook - Fastify175 internally monitors the error invocation to avoid infinite loops for errors176 thrown in the reply phases of the lifecycle. (those after the route handler)177 178When utilizing Fastify's custom error handling through [`setErrorHandler`](./Server.md#seterrorhandler),179you should be aware of how errors are propagated between custom and default180error handlers.181 182If a plugin's error handler re-throws an error, and the error is not an183instance of [Error](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error)184(as seen in the `/bad` route in the following example), it will not propagate185to the parent context error handler. Instead, it will be caught by the default186error handler.187 188To ensure consistent error handling, it is recommended to throw instances of189`Error`. For instance, in the following example, replacing `throw 'foo'` with190`throw new Error('foo')` in the `/bad` route ensures that errors propagate through191the custom error handling chain as intended. This practice helps avoid potential192pitfalls when working with custom error handling in Fastify.193 194For example:195```js196const Fastify = require('fastify')197 198// Instantiate the framework199const fastify = Fastify({200 logger: true201})202 203// Register parent error handler204fastify.setErrorHandler((error, request, reply) => {205 reply.status(500).send({ ok: false })206})207 208fastify.register((app, options, next) => {209 // Register child error handler210 fastify.setErrorHandler((error, request, reply) => {211 throw error212 })213 214 fastify.get('/bad', async () => {215 // Throws a non-Error type, 'bar'216 throw 'foo'217 })218 219 fastify.get('/good', async () => {220 // Throws an Error instance, 'bar'221 throw new Error('bar')222 })223 224 next()225})226 227// Run the server228fastify.listen({ port: 3000 }, function (err, address) {229 if (err) {230 fastify.log.error(err)231 process.exit(1)232 }233 // Server is listening at ${address}234})235```236 237### Fastify Error Codes238<a id="fastify-error-codes"></a>239 240You can access `errorCodes` for mapping:241```js242// ESM243import { errorCodes } from 'fastify'244 245// CommonJs246const errorCodes = require('fastify').errorCodes247```248 249For example:250```js251const Fastify = require('fastify')252 253// Instantiate the framework254const fastify = Fastify({255 logger: true256})257 258// Declare a route259fastify.get('/', function (request, reply) {260 reply.code('bad status code').send({ hello: 'world' })261})262 263fastify.setErrorHandler(function (error, request, reply) {264 if (error instanceof Fastify.errorCodes.FST_ERR_BAD_STATUS_CODE) {265 // Log error266 this.log.error(error)267 // Send error response268 reply.status(500).send({ ok: false })269 } else {270 // fastify will use parent error handler to handle this271 reply.send(error)272 }273})274 275// Run the server!276fastify.listen({ port: 3000 }, function (err, address) {277 if (err) {278 fastify.log.error(err)279 process.exit(1)280 }281 // Server is now listening on ${address}282})283```284 285Below is a table with all the error codes that Fastify uses.286 287| Code | Description | How to solve | Discussion |288|------|-------------|--------------|------------|289| <a id="fst_err_not_found">FST_ERR_NOT_FOUND</a> | 404 Not Found | - | [#1168](https://github.com/fastify/fastify/pull/1168) |290| <a id="fst_err_options_not_obj">FST_ERR_OPTIONS_NOT_OBJ</a> | Fastify options wrongly specified. | Fastify options should be an object. | [#4554](https://github.com/fastify/fastify/pull/4554) |291| <a id="fst_err_qsp_not_fn">FST_ERR_QSP_NOT_FN</a> | QueryStringParser wrongly specified. | QueryStringParser option should be a function. | [#4554](https://github.com/fastify/fastify/pull/4554) |292| <a id="fst_err_schema_controller_bucket_opt_not_fn">FST_ERR_SCHEMA_CONTROLLER_BUCKET_OPT_NOT_FN</a> | SchemaController.bucket wrongly specified. | SchemaController.bucket option should be a function. | [#4554](https://github.com/fastify/fastify/pull/4554) |293| <a id="fst_err_schema_error_formatter_not_fn">FST_ERR_SCHEMA_ERROR_FORMATTER_NOT_FN</a> | SchemaErrorFormatter option wrongly specified. | SchemaErrorFormatter option should be a non async function. | [#4554](https://github.com/fastify/fastify/pull/4554) |294| <a id="fst_err_ajv_custom_options_opt_not_obj">FST_ERR_AJV_CUSTOM_OPTIONS_OPT_NOT_OBJ</a> | ajv.customOptions wrongly specified. | ajv.customOptions option should be an object. | [#4554](https://github.com/fastify/fastify/pull/4554) |295| <a id="fst_err_ajv_custom_options_opt_not_arr">FST_ERR_AJV_CUSTOM_OPTIONS_OPT_NOT_ARR</a> | ajv.plugins option wrongly specified. | ajv.plugins option should be an array. | [#4554](https://github.com/fastify/fastify/pull/4554) |296| <a id="fst_err_ctp_already_present">FST_ERR_CTP_ALREADY_PRESENT</a> | The parser for this content type was already registered. | Use a different content type or delete the already registered parser. | [#1168](https://github.com/fastify/fastify/pull/1168) |297| <a id="fst_err_ctp_invalid_type">FST_ERR_CTP_INVALID_TYPE</a> | `Content-Type` wrongly specified | The `Content-Type` should be a string. | [#1168](https://github.com/fastify/fastify/pull/1168) |298| <a id="fst_err_ctp_empty_type">FST_ERR_CTP_EMPTY_TYPE</a> | `Content-Type` is an empty string. | `Content-Type` cannot be an empty string. | [#1168](https://github.com/fastify/fastify/pull/1168) |299| <a id="fst_err_ctp_invalid_handler">FST_ERR_CTP_INVALID_HANDLER</a> | Invalid handler for the content type. | Use a different handler. | [#1168](https://github.com/fastify/fastify/pull/1168) |300| <a id="fst_err_ctp_invalid_parse_type">FST_ERR_CTP_INVALID_PARSE_TYPE</a> | The provided parse type is not supported. | Accepted values are <code>string</code> or <code>buffer</code>. | [#1168](https://github.com/fastify/fastify/pull/1168) |301| <a id="fst_err_ctp_body_too_large">FST_ERR_CTP_BODY_TOO_LARGE</a> | The request body is larger than the provided limit. | Increase the limit in the Fastify server instance setting: [bodyLimit](./Server.md#bodylimit) | [#1168](https://github.com/fastify/fastify/pull/1168) |302| <a id="fst_err_ctp_invalid_media_type">FST_ERR_CTP_INVALID_MEDIA_TYPE</a> | The received media type is not supported (i.e. there is no suitable `Content-Type` parser for it). | Use a different content type. | [#1168](https://github.com/fastify/fastify/pull/1168) |303| <a id="fst_err_ctp_invalid_content_length">FST_ERR_CTP_INVALID_CONTENT_LENGTH</a> | Request body size did not match <code>Content-Length</code>. | Check the request body size and the <code>Content-Length</code> header. | [#1168](https://github.com/fastify/fastify/pull/1168) |304| <a id="fst_err_ctp_empty_json_body">FST_ERR_CTP_EMPTY_JSON_BODY</a> | Body cannot be empty when content-type is set to <code>application/json</code>. | Check the request body. | [#1253](https://github.com/fastify/fastify/pull/1253) |305| <a id="fst_err_ctp_instance_already_started">FST_ERR_CTP_INSTANCE_ALREADY_STARTED</a> | Fastify is already started. | - | [#4554](https://github.com/fastify/fastify/pull/4554) |306| <a id="fst_err_instance_already_listening">FST_ERR_INSTANCE_ALREADY_LISTENING</a> | Fastify instance is already listening. | - | [#4554](https://github.com/fastify/fastify/pull/4554) |307| <a id="fst_err_dec_already_present">FST_ERR_DEC_ALREADY_PRESENT</a> | A decorator with the same name is already registered. | Use a different decorator name. | [#1168](https://github.com/fastify/fastify/pull/1168) |308| <a id="fst_err_dec_dependency_invalid_type">FST_ERR_DEC_DEPENDENCY_INVALID_TYPE</a> | The dependencies of decorator must be of type `Array`. | Use an array for the dependencies. | [#3090](https://github.com/fastify/fastify/pull/3090) |309| <a id="fst_err_dec_missing_dependency">FST_ERR_DEC_MISSING_DEPENDENCY</a> | The decorator cannot be registered due to a missing dependency. | Register the missing dependency. | [#1168](https://github.com/fastify/fastify/pull/1168) |310| <a id="fst_err_dec_after_start">FST_ERR_DEC_AFTER_START</a> | The decorator cannot be added after start. | Add the decorator before starting the server. | [#2128](https://github.com/fastify/fastify/pull/2128) |311| <a id="fst_err_dec_reference_type">FST_ERR_DEC_REFERENCE_TYPE</a> | The decorator cannot be a reference type. | Define the decorator with a getter/setter interface or an empty decorator with a hook. | [#5462](https://github.com/fastify/fastify/pull/5462) |312| <a id="fst_err_hook_invalid_type">FST_ERR_HOOK_INVALID_TYPE</a> | The hook name must be a string. | Use a string for the hook name. | [#1168](https://github.com/fastify/fastify/pull/1168) |313| <a id="fst_err_hook_invalid_handler">FST_ERR_HOOK_INVALID_HANDLER</a> | The hook callback must be a function. | Use a function for the hook callback. | [#1168](https://github.com/fastify/fastify/pull/1168) |314| <a id="fst_err_hook_invalid_async_handler">FST_ERR_HOOK_INVALID_ASYNC_HANDLER</a> | Async function has too many arguments. Async hooks should not use the `done` argument. | Remove the `done` argument from the async hook. | [#4367](https://github.com/fastify/fastify/pull/4367) |315| <a id="fst_err_hook_not_supported">FST_ERR_HOOK_NOT_SUPPORTED</a> | The hook is not supported. | Use a supported hook. | [#4554](https://github.com/fastify/fastify/pull/4554) |316| <a id="fst_err_missing_middleware">FST_ERR_MISSING_MIDDLEWARE</a> | You must register a plugin for handling middlewares, visit [`Middleware`](./Middleware.md) for more info. | Register a plugin for handling middlewares. | [#2014](https://github.com/fastify/fastify/pull/2014) |317| <a id="fst_err_hook_timeout">FST_ERR_HOOK_TIMEOUT</a> | A callback for a hook timed out. | Increase the timeout for the hook. | [#3106](https://github.com/fastify/fastify/pull/3106) |318| <a id="fst_err_log_invalid_destination">FST_ERR_LOG_INVALID_DESTINATION</a> | The logger does not accept the specified destination. | Use a `'stream'` or a `'file'` as the destination. | [#1168](https://github.com/fastify/fastify/pull/1168) |319| <a id="fst_err_log_invalid_logger">FST_ERR_LOG_INVALID_LOGGER</a> | The logger should have all these methods: `'info'`, `'error'`, `'debug'`, `'fatal'`, `'warn'`, `'trace'`, `'child'`. | Use a logger with all the required methods. | [#4520](https://github.com/fastify/fastify/pull/4520) |320| <a id="fst_err_log_invalid_logger_instance">FST_ERR_LOG_INVALID_LOGGER_INSTANCE</a> | The `loggerInstance` only accepts a logger instance, not a configuration object. | To pass a configuration object, use `'logger'` instead. | [#5020](https://github.com/fastify/fastify/pull/5020) |321| <a id="fst_err_log_invalid_logger_config">FST_ERR_LOG_INVALID_LOGGER_CONFIG</a> | The logger option only accepts a configuration object, not a logger instance. | To pass an instance, use `'loggerInstance'` instead. | [#5020](https://github.com/fastify/fastify/pull/5020) |322| <a id="fst_err_log_logger_and_logger_instance_provided">FST_ERR_LOG_LOGGER_AND_LOGGER_INSTANCE_PROVIDED</a> | You cannot provide both `'logger'` and `'loggerInstance'`. | Please provide only one option. | [#5020](https://github.com/fastify/fastify/pull/5020) |323| <a id="fst_err_rep_invalid_payload_type">FST_ERR_REP_INVALID_PAYLOAD_TYPE</a> | Reply payload can be either a `string` or a `Buffer`. | Use a `string` or a `Buffer` for the payload. | [#1168](https://github.com/fastify/fastify/pull/1168) |324| <a id="fst_err_rep_response_body_consumed">FST_ERR_REP_RESPONSE_BODY_CONSUMED</a> | Using `Response` as reply payload, but the body is being consumed. | Make sure you don't consume the `Response.body` | [#5286](https://github.com/fastify/fastify/pull/5286) |325| <a id="fst_err_rep_readable_stream_locked">FST_ERR_REP_READABLE_STREAM_LOCKED</a> | Using `ReadableStream` as reply payload, but locked with another reader. | Make sure you don't call the `Readable.getReader` before sending or release lock with `reader.releaseLock()` before sending. | [#5920](https://github.com/fastify/fastify/pull/5920) |326| <a id="fst_err_rep_already_sent">FST_ERR_REP_ALREADY_SENT</a> | A response was already sent. | - | [#1336](https://github.com/fastify/fastify/pull/1336) |327| <a id="fst_err_rep_sent_value">FST_ERR_REP_SENT_VALUE</a> | The only possible value for `reply.sent` is `true`. | - | [#1336](https://github.com/fastify/fastify/pull/1336) |328| <a id="fst_err_send_inside_onerr">FST_ERR_SEND_INSIDE_ONERR</a> | You cannot use `send` inside the `onError` hook. | - | [#1348](https://github.com/fastify/fastify/pull/1348) |329| <a id="fst_err_send_undefined_err">FST_ERR_SEND_UNDEFINED_ERR</a> | Undefined error has occurred. | - | [#2074](https://github.com/fastify/fastify/pull/2074) |330| <a id="fst_err_bad_status_code">FST_ERR_BAD_STATUS_CODE</a> | The status code is not valid. | Use a valid status code. | [#2082](https://github.com/fastify/fastify/pull/2082) |331| <a id="fst_err_bad_trailer_name">FST_ERR_BAD_TRAILER_NAME</a> | Called `reply.trailer` with an invalid header name. | Use a valid header name. | [#3794](https://github.com/fastify/fastify/pull/3794) |332| <a id="fst_err_bad_trailer_value">FST_ERR_BAD_TRAILER_VALUE</a> | Called `reply.trailer` with an invalid type. Expected a function. | Use a function. | [#3794](https://github.com/fastify/fastify/pull/3794) |333| <a id="fst_err_failed_error_serialization">FST_ERR_FAILED_ERROR_SERIALIZATION</a> | Failed to serialize an error. | - | [#4601](https://github.com/fastify/fastify/pull/4601) |334| <a id="fst_err_missing_serialization_fn">FST_ERR_MISSING_SERIALIZATION_FN</a> | Missing serialization function. | Add a serialization function. | [#3970](https://github.com/fastify/fastify/pull/3970) |335| <a id="fst_err_missing_contenttype_serialization_fn">FST_ERR_MISSING_CONTENTTYPE_SERIALIZATION_FN</a> | Missing `Content-Type` serialization function. | Add a serialization function. | [#4264](https://github.com/fastify/fastify/pull/4264) |336| <a id="fst_err_req_invalid_validation_invocation">FST_ERR_REQ_INVALID_VALIDATION_INVOCATION</a> | Invalid validation invocation. Missing validation function for HTTP part nor schema provided. | Add a validation function. | [#3970](https://github.com/fastify/fastify/pull/3970) |337| <a id="fst_err_sch_missing_id">FST_ERR_SCH_MISSING_ID</a> | The schema provided does not have `$id` property. | Add a `$id` property. | [#1168](https://github.com/fastify/fastify/pull/1168) |338| <a id="fst_err_sch_already_present">FST_ERR_SCH_ALREADY_PRESENT</a> | A schema with the same `$id` already exists. | Use a different `$id`. | [#1168](https://github.com/fastify/fastify/pull/1168) |339| <a id="fst_err_sch_content_missing_schema">FST_ERR_SCH_CONTENT_MISSING_SCHEMA</a> | A schema is missing for the corresponding content type. | Add a schema. | [#4264](https://github.com/fastify/fastify/pull/4264) |340| <a id="fst_err_sch_duplicate">FST_ERR_SCH_DUPLICATE</a> | Schema with the same attribute already present! | Use a different attribute. | [#1954](https://github.com/fastify/fastify/pull/1954) |341| <a id="fst_err_sch_validation_build">FST_ERR_SCH_VALIDATION_BUILD</a> | The JSON schema provided for validation to a route is not valid. | Fix the JSON schema. | [#2023](https://github.com/fastify/fastify/pull/2023) |342| <a id="fst_err_sch_serialization_build">FST_ERR_SCH_SERIALIZATION_BUILD</a> | The JSON schema provided for serialization of a route response is not valid. | Fix the JSON schema. | [#2023](https://github.com/fastify/fastify/pull/2023) |343| <a id="fst_err_sch_response_schema_not_nested_2xx">FST_ERR_SCH_RESPONSE_SCHEMA_NOT_NESTED_2XX</a> | Response schemas should be nested under a valid status code (2XX). | Use a valid status code. | [#4554](https://github.com/fastify/fastify/pull/4554) |344| <a id="fst_err_http2_invalid_version">FST_ERR_HTTP2_INVALID_VERSION</a> | HTTP2 is available only from node >= 8.8.1. | Use a higher version of node. | [#1346](https://github.com/fastify/fastify/pull/1346) |345| <a id="fst_err_init_opts_invalid">FST_ERR_INIT_OPTS_INVALID</a> | Invalid initialization options. | Use valid initialization options. | [#1471](https://github.com/fastify/fastify/pull/1471) |346| <a id="fst_err_force_close_connections_idle_not_available">FST_ERR_FORCE_CLOSE_CONNECTIONS_IDLE_NOT_AVAILABLE</a> | Cannot set forceCloseConnections to `idle` as your HTTP server does not support `closeIdleConnections` method. | Use a different value for `forceCloseConnections`. | [#3925](https://github.com/fastify/fastify/pull/3925) |347| <a id="fst_err_duplicated_route">FST_ERR_DUPLICATED_ROUTE</a> | The HTTP method already has a registered controller for that URL. | Use a different URL or register the controller for another HTTP method. | [#2954](https://github.com/fastify/fastify/pull/2954) |348| <a id="fst_err_bad_url">FST_ERR_BAD_URL</a> | The router received an invalid URL. | Use a valid URL. | [#2106](https://github.com/fastify/fastify/pull/2106) |349| <a id="fst_err_async_constraint">FST_ERR_ASYNC_CONSTRAINT</a> | The router received an error when using asynchronous constraints. | - | [#4323](https://github.com/fastify/fastify/pull/4323) |350| <a id="fst_err_invalid_url">FST_ERR_INVALID_URL</a> | URL must be a string. | Use a string for the URL. | [#3653](https://github.com/fastify/fastify/pull/3653) |351| <a id="fst_err_route_options_not_obj">FST_ERR_ROUTE_OPTIONS_NOT_OBJ</a> | Options for the route must be an object. | Use an object for the route options. | [#4554](https://github.com/fastify/fastify/pull/4554) |352| <a id="fst_err_route_duplicated_handler">FST_ERR_ROUTE_DUPLICATED_HANDLER</a> | Duplicate handler for the route is not allowed. | Use a different handler. | [#4554](https://github.com/fastify/fastify/pull/4554) |353| <a id="fst_err_route_handler_not_fn">FST_ERR_ROUTE_HANDLER_NOT_FN</a> | Handler for the route must be a function. | Use a function for the handler. | [#4554](https://github.com/fastify/fastify/pull/4554) |354| <a id="fst_err_route_missing_handler">FST_ERR_ROUTE_MISSING_HANDLER</a> | Missing handler function for the route. | Add a handler function. | [#4554](https://github.com/fastify/fastify/pull/4554) |355| <a id="fst_err_route_method_invalid">FST_ERR_ROUTE_METHOD_INVALID</a> | Method is not a valid value. | Use a valid value for the method. | [#4750](https://github.com/fastify/fastify/pull/4750) |356| <a id="fst_err_route_method_not_supported">FST_ERR_ROUTE_METHOD_NOT_SUPPORTED</a> | Method is not supported for the route. | Use a supported method. | [#4554](https://github.com/fastify/fastify/pull/4554) |357| <a id="fst_err_route_body_validation_schema_not_supported">FST_ERR_ROUTE_BODY_VALIDATION_SCHEMA_NOT_SUPPORTED</a> | Body validation schema route is not supported. | Use a different different method for the route. | [#4554](https://github.com/fastify/fastify/pull/4554) |358| <a id="fst_err_route_body_limit_option_not_int">FST_ERR_ROUTE_BODY_LIMIT_OPTION_NOT_INT</a> | `bodyLimit` option must be an integer. | Use an integer for the `bodyLimit` option. | [#4554](https://github.com/fastify/fastify/pull/4554) |359| <a id="fst_err_route_rewrite_not_str">FST_ERR_ROUTE_REWRITE_NOT_STR</a> | `rewriteUrl` needs to be of type `string`. | Use a string for the `rewriteUrl`. | [#4554](https://github.com/fastify/fastify/pull/4554) |360| <a id="fst_err_reopened_close_server">FST_ERR_REOPENED_CLOSE_SERVER</a> | Fastify has already been closed and cannot be reopened. | - | [#2415](https://github.com/fastify/fastify/pull/2415) |361| <a id="fst_err_reopened_server">FST_ERR_REOPENED_SERVER</a> | Fastify is already listening. | - | [#2415](https://github.com/fastify/fastify/pull/2415) |362| <a id="fst_err_plugin_version_mismatch">FST_ERR_PLUGIN_VERSION_MISMATCH</a> | Installed Fastify plugin mismatched expected version. | Use a compatible version of the plugin. | [#2549](https://github.com/fastify/fastify/pull/2549) |363| <a id="fst_err_plugin_callback_not_fn">FST_ERR_PLUGIN_CALLBACK_NOT_FN</a> | Callback for a hook is not a function. | Use a function for the callback. | [#3106](https://github.com/fastify/fastify/pull/3106) |364| <a id="fst_err_plugin_not_valid">FST_ERR_PLUGIN_NOT_VALID</a> | Plugin must be a function or a promise. | Use a function or a promise for the plugin. | [#3106](https://github.com/fastify/fastify/pull/3106) |365| <a id="fst_err_root_plg_booted">FST_ERR_ROOT_PLG_BOOTED</a> | Root plugin has already booted. | - | [#3106](https://github.com/fastify/fastify/pull/3106) |366| <a id="fst_err_parent_plugin_booted">FST_ERR_PARENT_PLUGIN_BOOTED</a> | Impossible to load plugin because the parent (mapped directly from `avvio`) | - | [#3106](https://github.com/fastify/fastify/pull/3106) |367| <a id="fst_err_plugin_timeout">FST_ERR_PLUGIN_TIMEOUT</a> | Plugin did not start in time. | Increase the timeout for the plugin. | [#3106](https://github.com/fastify/fastify/pull/3106) |368| <a id="fst_err_plugin_not_present_in_instance">FST_ERR_PLUGIN_NOT_PRESENT_IN_INSTANCE</a> | The decorator is not present in the instance. | - | [#4554](https://github.com/fastify/fastify/pull/4554) |369| <a id="fst_err_plugin_invalid_async_handler">FST_ERR_PLUGIN_INVALID_ASYNC_HANDLER</a> | The plugin being registered mixes async and callback styles. | - | [#5141](https://github.com/fastify/fastify/pull/5141) |370| <a id="fst_err_validation">FST_ERR_VALIDATION</a> | The Request failed the payload validation. | Check the request payload. | [#4824](https://github.com/fastify/fastify/pull/4824) |371| <a id="fst_err_listen_options_invalid">FST_ERR_LISTEN_OPTIONS_INVALID</a> | Invalid listen options. | Check the listen options. | [#4886](https://github.com/fastify/fastify/pull/4886) |372| <a id="fst_err_error_handler_not_fn">FST_ERR_ERROR_HANDLER_NOT_FN</a> | Error Handler must be a function | Provide a function to `setErrorHandler`. | [#5317](https://github.com/fastify/fastify/pull/5317) |373 374 