fastify 4.24.2 → 4.25.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (67) hide show
  1. package/README.md +7 -2
  2. package/SECURITY.md +27 -0
  3. package/docs/Guides/Ecosystem.md +18 -6
  4. package/docs/Guides/Getting-Started.md +3 -3
  5. package/docs/Guides/Plugins-Guide.md +2 -2
  6. package/docs/Guides/Style-Guide.md +7 -7
  7. package/docs/Reference/ContentTypeParser.md +2 -0
  8. package/docs/Reference/Errors.md +171 -397
  9. package/docs/Reference/Hooks.md +8 -2
  10. package/docs/Reference/Index.md +2 -0
  11. package/docs/Reference/Reply.md +16 -5
  12. package/docs/Reference/Request.md +1 -1
  13. package/docs/Reference/Routes.md +5 -5
  14. package/docs/Reference/TypeScript.md +1 -1
  15. package/docs/Reference/Warnings.md +77 -0
  16. package/examples/use-plugin.js +2 -0
  17. package/fastify.js +37 -20
  18. package/integration/server.js +2 -0
  19. package/lib/decorate.js +2 -2
  20. package/lib/errors.js +1 -1
  21. package/lib/hooks.js +1 -1
  22. package/lib/pluginUtils.js +10 -1
  23. package/lib/reply.js +5 -5
  24. package/lib/request.js +14 -7
  25. package/lib/route.js +9 -5
  26. package/lib/server.js +20 -27
  27. package/lib/validation.js +5 -5
  28. package/lib/warnings.js +110 -40
  29. package/package.json +4 -4
  30. package/test/buffer.test.js +2 -0
  31. package/test/bundler/esbuild/src/fail-plugin-version.js +2 -0
  32. package/test/bundler/esbuild/src/index.js +2 -0
  33. package/test/bundler/webpack/src/fail-plugin-version.js +2 -0
  34. package/test/bundler/webpack/src/index.js +2 -0
  35. package/test/bundler/webpack/webpack.config.js +2 -0
  36. package/test/close-pipelining.test.js +4 -4
  37. package/test/close.test.js +3 -3
  38. package/test/constrained-routes.test.js +24 -24
  39. package/test/decorator.test.js +27 -22
  40. package/test/default-route.test.js +7 -7
  41. package/test/fastify-instance.test.js +120 -0
  42. package/test/hooks.on-ready.test.js +16 -0
  43. package/test/hooks.test.js +1 -3
  44. package/test/http2/constraint.test.js +1 -1
  45. package/test/internals/errors.test.js +28 -3
  46. package/test/internals/reply.test.js +33 -9
  47. package/test/logger/instantiation.test.js +2 -1
  48. package/test/plugin.4.test.js +28 -0
  49. package/test/register.test.js +5 -5
  50. package/test/reply-trailers.test.js +1 -1
  51. package/test/route.7.test.js +7 -6
  52. package/test/schema-examples.test.js +2 -2
  53. package/test/schema-feature.test.js +11 -11
  54. package/test/server.test.js +51 -0
  55. package/test/types/hooks.test-d.ts +124 -1
  56. package/test/types/instance.test-d.ts +12 -0
  57. package/test/types/logger.test-d.ts +14 -0
  58. package/test/types/reply.test-d.ts +25 -6
  59. package/test/types/request.test-d.ts +3 -2
  60. package/test/types/route.test-d.ts +38 -0
  61. package/test/versioned-routes.test.js +7 -6
  62. package/types/hooks.d.ts +183 -0
  63. package/types/instance.d.ts +12 -12
  64. package/types/reply.d.ts +7 -10
  65. package/types/request.d.ts +2 -1
  66. package/types/route.d.ts +31 -26
  67. package/types/utils.d.ts +10 -0
@@ -3,6 +3,95 @@
3
3
  ## Errors
4
4
  <a id="errors"></a>
5
5
 
6
+ **Table of contents**
7
+ - [Errors](#errors)
8
+ - [Error Handling In Node.js](#error-handling-in-node.js)
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_VERSION_CONSTRAINT_NOT_STR](#fst_err_version_constraint_not_str)
24
+ - [FST_ERR_CTP_ALREADY_PRESENT](#fst_err_ctp_already_present)
25
+ - [FST_ERR_CTP_INVALID_TYPE](#fst_err_ctp_invalid_type)
26
+ - [FST_ERR_CTP_EMPTY_TYPE](#fst_err_ctp_empty_type)
27
+ - [FST_ERR_CTP_INVALID_HANDLER](#fst_err_ctp_invalid_handler)
28
+ - [FST_ERR_CTP_INVALID_PARSE_TYPE](#fst_err_ctp_invalid_parse_type)
29
+ - [FST_ERR_CTP_BODY_TOO_LARGE](#fst_err_ctp_body_too_large)
30
+ - [FST_ERR_CTP_INVALID_MEDIA_TYPE](#fst_err_ctp_invalid_media_type)
31
+ - [FST_ERR_CTP_INVALID_CONTENT_LENGTH](#fst_err_ctp_invalid_content_length)
32
+ - [FST_ERR_CTP_EMPTY_JSON_BODY](#fst_err_ctp_empty_json_body)
33
+ - [FST_ERR_CTP_INSTANCE_ALREADY_STARTED](#fst_err_ctp_instance_already_started)
34
+ - [FST_ERR_INSTANCE_ALREADY_LISTENING](#fst_err_instance_already_listening)
35
+ - [FST_ERR_DEC_ALREADY_PRESENT](#fst_err_dec_already_present)
36
+ - [FST_ERR_DEC_DEPENDENCY_INVALID_TYPE](#fst_err_dec_dependency_invalid_type)
37
+ - [FST_ERR_DEC_MISSING_DEPENDENCY](#fst_err_dec_missing_dependency)
38
+ - [FST_ERR_DEC_AFTER_START](#fst_err_dec_after_start)
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_REP_INVALID_PAYLOAD_TYPE](#fst_err_rep_invalid_payload_type)
48
+ - [FST_ERR_REP_ALREADY_SENT](#fst_err_rep_already_sent)
49
+ - [FST_ERR_REP_SENT_VALUE](#fst_err_rep_sent_value)
50
+ - [FST_ERR_SEND_INSIDE_ONERR](#fst_err_send_inside_onerr)
51
+ - [FST_ERR_SEND_UNDEFINED_ERR](#fst_err_send_undefined_err)
52
+ - [FST_ERR_BAD_STATUS_CODE](#fst_err_bad_status_code)
53
+ - [FST_ERR_BAD_TRAILER_NAME](#fst_err_bad_trailer_name)
54
+ - [FST_ERR_BAD_TRAILER_VALUE](#fst_err_bad_trailer_value)
55
+ - [FST_ERR_FAILED_ERROR_SERIALIZATION](#fst_err_failed_error_serialization)
56
+ - [FST_ERR_MISSING_SERIALIZATION_FN](#fst_err_missing_serialization_fn)
57
+ - [FST_ERR_MISSING_CONTENTTYPE_SERIALIZATION_FN](#fst_err_missing_contenttype_serialization_fn)
58
+ - [FST_ERR_REQ_INVALID_VALIDATION_INVOCATION](#fst_err_req_invalid_validation_invocation)
59
+ - [FST_ERR_SCH_MISSING_ID](#fst_err_sch_missing_id)
60
+ - [FST_ERR_SCH_ALREADY_PRESENT](#fst_err_sch_already_present)
61
+ - [FST_ERR_SCH_CONTENT_MISSING_SCHEMA](#fst_err_sch_content_missing_schema)
62
+ - [FST_ERR_SCH_DUPLICATE](#fst_err_sch_duplicate)
63
+ - [FST_ERR_SCH_VALIDATION_BUILD](#fst_err_sch_validation_build)
64
+ - [FST_ERR_SCH_SERIALIZATION_BUILD](#fst_err_sch_serialization_build)
65
+ - [FST_ERR_SCH_RESPONSE_SCHEMA_NOT_NESTED_2XX](#fst_err_sch_response_schema_not_nested_2xx)
66
+ - [FST_ERR_HTTP2_INVALID_VERSION](#fst_err_http2_invalid_version)
67
+ - [FST_ERR_INIT_OPTS_INVALID](#fst_err_init_opts_invalid)
68
+ - [FST_ERR_FORCE_CLOSE_CONNECTIONS_IDLE_NOT_AVAILABLE](#fst_err_force_close_connections_idle_not_available)
69
+ - [FST_ERR_DUPLICATED_ROUTE](#fst_err_duplicated_route)
70
+ - [FST_ERR_BAD_URL](#fst_err_bad_url)
71
+ - [FST_ERR_ASYNC_CONSTRAINT](#fst_err_async_constraint)
72
+ - [FST_ERR_DEFAULT_ROUTE_INVALID_TYPE](#fst_err_default_route_invalid_type)
73
+ - [FST_ERR_INVALID_URL](#fst_err_invalid_url)
74
+ - [FST_ERR_ROUTE_OPTIONS_NOT_OBJ](#fst_err_route_options_not_obj)
75
+ - [FST_ERR_ROUTE_DUPLICATED_HANDLER](#fst_err_route_duplicated_handler)
76
+ - [FST_ERR_ROUTE_HANDLER_NOT_FN](#fst_err_route_handler_not_fn)
77
+ - [FST_ERR_ROUTE_MISSING_HANDLER](#fst_err_route_missing_handler)
78
+ - [FST_ERR_ROUTE_METHOD_INVALID](#fst_err_route_method_invalid)
79
+ - [FST_ERR_ROUTE_METHOD_NOT_SUPPORTED](#fst_err_route_method_not_supported)
80
+ - [FST_ERR_ROUTE_BODY_VALIDATION_SCHEMA_NOT_SUPPORTED](#fst_err_route_body_validation_schema_not_supported)
81
+ - [FST_ERR_ROUTE_BODY_LIMIT_OPTION_NOT_INT](#fst_err_route_body_limit_option_not_int)
82
+ - [FST_ERR_ROUTE_REWRITE_NOT_STR](#fst_err_route_rewrite_not_str)
83
+ - [FST_ERR_REOPENED_CLOSE_SERVER](#fst_err_reopened_close_server)
84
+ - [FST_ERR_REOPENED_SERVER](#fst_err_reopened_server)
85
+ - [FST_ERR_PLUGIN_VERSION_MISMATCH](#fst_err_plugin_version_mismatch)
86
+ - [FST_ERR_PLUGIN_CALLBACK_NOT_FN](#fst_err_plugin_callback_not_fn)
87
+ - [FST_ERR_PLUGIN_NOT_VALID](#fst_err_plugin_not_valid)
88
+ - [FST_ERR_ROOT_PLG_BOOTED](#fst_err_root_plg_booted)
89
+ - [FST_ERR_PARENT_PLUGIN_BOOTED](#fst_err_parent_plugin_booted)
90
+ - [FST_ERR_PLUGIN_TIMEOUT](#fst_err_plugin_timeout)
91
+ - [FST_ERR_PLUGIN_NOT_PRESENT_IN_INSTANCE](#fst_err_plugin_not_present_in_instance)
92
+ - [FST_ERR_VALIDATION](#fst_err_validation)
93
+ - [FST_ERR_LISTEN_OPTIONS_INVALID](#fst_err_listen_options_invalid)
94
+
6
95
  ### Error Handling In Node.js
7
96
  <a id="error-handling"></a>
8
97
 
@@ -128,401 +217,86 @@ fastify.listen({ port: 3000 }, function (err, address) {
128
217
  })
129
218
  ```
130
219
 
131
- #### FST_ERR_NOT_FOUND
132
- <a id="FST_ERR_NOT_FOUND"></a>
133
-
134
- 404 Not Found.
135
-
136
- #### FST_ERR_OPTIONS_NOT_OBJ
137
- <a id="FST_ERR_OPTIONS_NOT_OBJ"></a>
138
-
139
- Fastify options must be an object.
140
-
141
- #### FST_ERR_QSP_NOT_FN
142
- <a id="FST_ERR_QSP_NOT_FN"></a>
143
-
144
- QueryStringParser option should be a function.
145
-
146
- #### FST_ERR_SCHEMA_CONTROLLER_BUCKET_OPT_NOT_FN
147
- <a id="FST_ERR_SCHEMA_CONTROLLER_BUCKET_OPT_NOT_FN"></a>
148
-
149
- SchemaController.bucket option should be a function.
150
-
151
- #### FST_ERR_SCHEMA_ERROR_FORMATTER_NOT_FN
152
- <a id="FST_ERR_SCHEMA_ERROR_FORMATTER_NOT_FN"></a>
153
-
154
- SchemaErrorFormatter option should be a non async function.
155
-
156
- #### FST_ERR_AJV_CUSTOM_OPTIONS_OPT_NOT_OBJ
157
- <a id="FST_ERR_AJV_CUSTOM_OPTIONS_OPT_NOT_OBJ"></a>
158
-
159
- ajv.customOptions option should be an object.
160
-
161
- #### FST_ERR_AJV_CUSTOM_OPTIONS_OPT_NOT_ARR
162
- <a id="FST_ERR_AJV_CUSTOM_OPTIONS_OPT_NOT_ARR"></a>
163
-
164
- ajv.plugins option should be an array.
165
-
166
- #### FST_ERR_VERSION_CONSTRAINT_NOT_STR
167
- <a id="FST_ERR_VERSION_CONSTRAINT_NOT_STR"></a>
168
-
169
- Version constraint should be a string.
170
-
171
- #### FST_ERR_CTP_ALREADY_PRESENT
172
- <a id="FST_ERR_CTP_ALREADY_PRESENT"></a>
173
-
174
- The parser for this content type was already registered.
175
-
176
- #### FST_ERR_CTP_INVALID_TYPE
177
- <a id="FST_ERR_CTP_INVALID_TYPE"></a>
178
-
179
- The `Content-Type` should be a string.
180
-
181
- #### FST_ERR_CTP_EMPTY_TYPE
182
- <a id="FST_ERR_CTP_EMPTY_TYPE"></a>
183
-
184
- The content type cannot be an empty string.
185
-
186
- #### FST_ERR_CTP_INVALID_HANDLER
187
- <a id="FST_ERR_CTP_INVALID_HANDLER"></a>
188
-
189
- An invalid handler was passed for the content type.
190
-
191
- #### FST_ERR_CTP_INVALID_PARSE_TYPE
192
- <a id="FST_ERR_CTP_INVALID_PARSE_TYPE"></a>
193
-
194
- The provided parse type is not supported. Accepted values are `string` or
195
- `buffer`.
196
-
197
- #### FST_ERR_CTP_BODY_TOO_LARGE
198
- <a id="FST_ERR_CTP_BODY_TOO_LARGE"></a>
199
-
200
- The request body is larger than the provided limit.
201
-
202
- This setting can be defined in the Fastify server instance:
203
- [`bodyLimit`](./Server.md#bodylimit)
204
-
205
- #### FST_ERR_CTP_INVALID_MEDIA_TYPE
206
- <a id="FST_ERR_CTP_INVALID_MEDIA_TYPE"></a>
207
-
208
- The received media type is not supported (i.e. there is no suitable
209
- `Content-Type` parser for it).
210
-
211
- #### FST_ERR_CTP_INVALID_CONTENT_LENGTH
212
- <a id="FST_ERR_CTP_INVALID_CONTENT_LENGTH"></a>
213
-
214
- Request body size did not match `Content-Length`.
215
-
216
- #### FST_ERR_CTP_EMPTY_JSON_BODY
217
- <a id="FST_ERR_CTP_EMPTY_JSON_BODY"></a>
218
-
219
- Body cannot be empty when content-type is set to `application/json`.
220
-
221
- #### FST_ERR_CTP_INSTANCE_ALREADY_STARTED
222
- <a id="FST_ERR_CTP_INSTANCE_ALREADY_STARTED"></a>
223
-
224
- Fastify is already started.
225
-
226
- #### FST_ERR_INSTANCE_ALREADY_LISTENING
227
- <a id="FST_ERR_INSTANCE_ALREADY_LISTENING"></a>
228
-
229
- Fastify instance is already listening.
230
-
231
- #### FST_ERR_DEC_ALREADY_PRESENT
232
- <a id="FST_ERR_DEC_ALREADY_PRESENT"></a>
233
-
234
- A decorator with the same name is already registered.
235
-
236
- #### FST_ERR_DEC_DEPENDENCY_INVALID_TYPE
237
- <a id="FST_ERR_DEC_DEPENDENCY_INVALID_TYPE"></a>
238
-
239
- The dependencies of decorator must be of type `Array`.
240
-
241
- #### FST_ERR_DEC_MISSING_DEPENDENCY
242
- <a id="FST_ERR_DEC_MISSING_DEPENDENCY"></a>
243
-
244
- The decorator cannot be registered due to a missing dependency.
245
-
246
- #### FST_ERR_DEC_AFTER_START
247
- <a id="FST_ERR_DEC_AFTER_START"></a>
248
-
249
- The decorator cannot be added after start.
250
-
251
- #### FST_ERR_HOOK_INVALID_TYPE
252
- <a id="FST_ERR_HOOK_INVALID_TYPE"></a>
253
-
254
- The hook name must be a string.
255
-
256
- #### FST_ERR_HOOK_INVALID_HANDLER
257
- <a id="FST_ERR_HOOK_INVALID_HANDLER"></a>
258
-
259
- The hook callback must be a function.
260
-
261
- #### FST_ERR_HOOK_INVALID_ASYNC_HANDLER
262
- <a id="FST_ERR_HOOK_INVALID_ASYNC_HANDLER"></a>
263
-
264
- Async function has too many arguments. Async hooks should not use the `done` argument.
265
-
266
- #### FST_ERR_HOOK_NOT_SUPPORTED
267
- <a id="FST_ERR_HOOK_NOT_SUPPORTED"></a>
268
-
269
- The hook is not supported.
270
-
271
- #### FST_ERR_MISSING_MIDDLEWARE
272
- <a id="FST_ERR_MISSING_MIDDLEWARE"></a>
273
-
274
- You must register a plugin for handling middlewares,
275
- visit [`Middleware`](./Middleware.md) for more info.
276
-
277
- #### FST_ERR_HOOK_TIMEOUT
278
- <a id="FST_ERR_HOOK_TIMEOUT"></a>
279
-
280
- A callback for a hook timed out
281
-
282
- #### FST_ERR_LOG_INVALID_DESTINATION
283
- <a id="FST_ERR_LOG_INVALID_DESTINATION"></a>
284
-
285
- The logger accepts either a `'stream'` or a `'file'` as the destination.
286
-
287
- #### FST_ERR_LOG_INVALID_LOGGER
288
- <a id="FST_ERR_LOG_INVALID_LOGGER"></a>
289
-
290
- The logger should have all these methods: `'info'`, `'error'`,
291
- `'debug'`, `'fatal'`, `'warn'`, `'trace'`, `'child'`.
292
-
293
- #### FST_ERR_REP_INVALID_PAYLOAD_TYPE
294
- <a id="FST_ERR_REP_INVALID_PAYLOAD_TYPE"></a>
295
-
296
- Reply payload can be either a `string` or a `Buffer`.
297
-
298
- #### FST_ERR_REP_ALREADY_SENT
299
- <a id="FST_ERR_REP_ALREADY_SENT"></a>
300
-
301
- A response was already sent.
302
-
303
- #### FST_ERR_REP_SENT_VALUE
304
- <a id="FST_ERR_REP_SENT_VALUE"></a>
305
-
306
- The only possible value for `reply.sent` is `true`.
307
-
308
- #### FST_ERR_SEND_INSIDE_ONERR
309
- <a id="FST_ERR_SEND_INSIDE_ONERR"></a>
310
-
311
- You cannot use `send` inside the `onError` hook.
312
-
313
- #### FST_ERR_SEND_UNDEFINED_ERR
314
- <a id="FST_ERR_SEND_UNDEFINED_ERR"></a>
315
-
316
- Undefined error has occurred.
317
-
318
- #### FST_ERR_BAD_STATUS_CODE
319
- <a id="FST_ERR_BAD_STATUS_CODE"></a>
320
-
321
- Called `reply` with an invalid status code.
322
-
323
- #### FST_ERR_BAD_TRAILER_NAME
324
- <a id="FST_ERR_BAD_TRAILER_NAME"></a>
325
-
326
- Called `reply.trailer` with an invalid header name.
327
-
328
- #### FST_ERR_BAD_TRAILER_VALUE
329
- <a id="FST_ERR_BAD_TRAILER_VALUE"></a>
330
-
331
- Called `reply.trailer` with an invalid type. Expected a function.
332
-
333
- #### FST_ERR_FAILED_ERROR_SERIALIZATION
334
- <a id="FST_ERR_FAILED_ERROR_SERIALIZATION"></a>
335
-
336
- Failed to serialize an error.
337
-
338
- #### FST_ERR_MISSING_SERIALIZATION_FN
339
- <a id="FST_ERR_MISSING_SERIALIZATION_FN"></a>
340
-
341
- Missing serialization function.
342
-
343
- #### FST_ERR_MISSING_CONTENTTYPE_SERIALIZATION_FN
344
- <a id="FST_ERR_MISSING_CONTENTTYPE_SERIALIZATION_FN"></a>
345
-
346
- Missing serialization function.
347
-
348
- #### FST_ERR_REQ_INVALID_VALIDATION_INVOCATION
349
- <a id="FST_ERR_REQ_INVALID_VALIDATION_INVOCATION"></a>
350
-
351
- Invalid validation invocation. Missing validation function for
352
- HTTP part nor schema provided.
353
-
354
- #### FST_ERR_SCH_MISSING_ID
355
- <a id="FST_ERR_SCH_MISSING_ID"></a>
356
-
357
- The schema provided does not have `$id` property.
358
-
359
- #### FST_ERR_SCH_ALREADY_PRESENT
360
- <a id="FST_ERR_SCH_ALREADY_PRESENT"></a>
361
-
362
- A schema with the same `$id` already exists.
363
-
364
- #### FST_ERR_SCH_CONTENT_MISSING_SCHEMA
365
- <a id="FST_ERR_SCH_CONTENT_MISSING_SCHEMA"></a>
366
-
367
- A schema is missing for the corresponding content type.
368
-
369
- #### FST_ERR_SCH_DUPLICATE
370
- <a id="FST_ERR_SCH_DUPLICATE"></a>
371
-
372
- Schema with the same `$id` already present!
373
-
374
- #### FST_ERR_SCH_VALIDATION_BUILD
375
- <a id="FST_ERR_SCH_VALIDATION_BUILD"></a>
376
-
377
- The JSON schema provided for validation to a route is not valid.
378
-
379
- #### FST_ERR_SCH_SERIALIZATION_BUILD
380
- <a id="FST_ERR_SCH_SERIALIZATION_BUILD"></a>
381
-
382
- The JSON schema provided for serialization of a route response is not valid.
383
-
384
- #### FST_ERR_SCH_RESPONSE_SCHEMA_NOT_NESTED_2XX
385
- <a id="FST_ERR_SCH_RESPONSE_SCHEMA_NOT_NESTED_2XX"></a>
386
-
387
- Response schemas should be nested under a valid status code (2XX).
388
-
389
- #### FST_ERR_HTTP2_INVALID_VERSION
390
- <a id="FST_ERR_HTTP2_INVALID_VERSION"></a>
391
-
392
- HTTP2 is available only from node >= 8.8.1.
393
-
394
- #### FST_ERR_INIT_OPTS_INVALID
395
- <a id="FST_ERR_INIT_OPTS_INVALID"></a>
396
-
397
- Invalid initialization options.
398
-
399
- #### FST_ERR_FORCE_CLOSE_CONNECTIONS_IDLE_NOT_AVAILABLE
400
- <a id="FST_ERR_FORCE_CLOSE_CONNECTIONS_IDLE_NOT_AVAILABLE"></a>
401
-
402
- Cannot set forceCloseConnections to `idle` as your HTTP server
403
- does not support `closeIdleConnections` method.
404
-
405
- #### FST_ERR_DUPLICATED_ROUTE
406
- <a id="FST_ERR_DUPLICATED_ROUTE"></a>
407
-
408
- The HTTP method already has a registered controller for that URL
409
-
410
- #### FST_ERR_BAD_URL
411
- <a id="FST_ERR_BAD_URL"></a>
412
-
413
- The router received an invalid url.
414
-
415
- #### FST_ERR_ASYNC_CONSTRAINT
416
- <a id="FST_ERR_ASYNC_CONSTRAINT"></a>
417
-
418
- The router received an error when using asynchronous constraints.
419
-
420
- #### FST_ERR_DEFAULT_ROUTE_INVALID_TYPE
421
- <a id="FST_ERR_DEFAULT_ROUTE_INVALID_TYPE"></a>
422
-
423
- The `defaultRoute` type should be a function.
424
-
425
- #### FST_ERR_INVALID_URL
426
- <a id="FST_ERR_INVALID_URL"></a>
427
-
428
- URL must be a string.
429
-
430
- #### FST_ERR_ROUTE_OPTIONS_NOT_OBJ
431
- <a id="FST_ERR_ROUTE_OPTIONS_NOT_OBJ"></a>
432
-
433
- Options for the route must be an object.
434
-
435
- #### FST_ERR_ROUTE_DUPLICATED_HANDLER
436
- <a id="FST_ERR_ROUTE_DUPLICATED_HANDLER"></a>
437
-
438
- Duplicate handler for the route is not allowed.
439
-
440
- #### FST_ERR_ROUTE_HANDLER_NOT_FN
441
- <a id="FST_ERR_ROUTE_HANDLER_NOT_FN"></a>
442
-
443
- Handler for the route must be a function.
444
-
445
- #### FST_ERR_ROUTE_MISSING_HANDLER
446
- <a id="FST_ERR_ROUTE_MISSING_HANDLER"></a>
447
-
448
- Missing handler function for the route.
449
-
450
- #### FST_ERR_ROUTE_METHOD_INVALID
451
- <a id="FST_ERR_ROUTE_METHOD_INVALID"></a>
452
-
453
- Method is not a valid value.
454
-
455
- #### FST_ERR_ROUTE_METHOD_NOT_SUPPORTED
456
- <a id="FST_ERR_ROUTE_METHOD_NOT_SUPPORTED"></a>
457
-
458
- Method is not supported for the route.
459
-
460
- #### FST_ERR_ROUTE_BODY_VALIDATION_SCHEMA_NOT_SUPPORTED
461
- <a id="FST_ERR_ROUTE_BODY_VALIDATION_SCHEMA_NOT_SUPPORTED"></a>
462
-
463
- Body validation schema route is not supported.
464
-
465
- #### FST_ERR_ROUTE_BODY_LIMIT_OPTION_NOT_INT
466
- <a id="FST_ERR_ROUTE_BODY_LIMIT_OPTION_NOT_INT"></a>
467
-
468
- BodyLimit option must be an integer.
469
-
470
- #### FST_ERR_ROUTE_REWRITE_NOT_STR
471
- <a id="FST_ERR_ROUTE_REWRITE_NOT_STR"></a>
472
-
473
- Rewrite url needs to be of type "string".
474
-
475
- #### FST_ERR_REOPENED_CLOSE_SERVER
476
- <a id="FST_ERR_REOPENED_CLOSE_SERVER"></a>
477
-
478
- Fastify has already been closed and cannot be reopened.
479
-
480
- #### FST_ERR_REOPENED_SERVER
481
- <a id="FST_ERR_REOPENED_SERVER"></a>
482
-
483
- Fastify is already listening.
484
-
485
- #### FST_ERR_PLUGIN_VERSION_MISMATCH
486
- <a id="FST_ERR_PLUGIN_VERSION_MISMATCH"></a>
487
-
488
- Installed Fastify plugin mismatched expected version.
489
-
490
- #### FST_ERR_PLUGIN_CALLBACK_NOT_FN
491
- <a id="FST_ERR_PLUGIN_CALLBACK_NOT_FN"></a>
492
-
493
- Callback for a hook is not a function (mapped directly from `avvio`)
494
-
495
- #### FST_ERR_PLUGIN_NOT_VALID
496
- <a id="FST_ERR_PLUGIN_NOT_VALID"></a>
497
-
498
- Plugin must be a function or a promise.
499
-
500
- #### FST_ERR_ROOT_PLG_BOOTED
501
- <a id="FST_ERR_ROOT_PLG_BOOTED"></a>
502
-
503
- Root plugin has already booted (mapped directly from `avvio`)
504
-
505
- #### FST_ERR_PARENT_PLUGIN_BOOTED
506
- <a id="FST_ERR_PARENT_PLUGIN_BOOTED"></a>
507
-
508
- Impossible to load plugin because the parent (mapped directly from `avvio`)
509
-
510
- #### FST_ERR_PLUGIN_TIMEOUT
511
- <a id="FST_ERR_PLUGIN_TIMEOUT"></a>
512
-
513
- Plugin did not start in time. Default timeout (in milliseconds): `10000`
514
-
515
- #### FST_ERR_PLUGIN_NOT_PRESENT_IN_INSTANCE
516
- <a id="FST_ERR_PLUGIN_NOT_PRESENT_IN_INSTANCE"></a>
517
-
518
- The decorator is not present in the instance.
519
-
520
- #### FST_ERR_VALIDATION
521
- <a id="FST_ERR_VALIDATION"></a>
522
-
523
- The Request failed the payload validation.
524
-
525
- #### FST_ERR_LISTEN_OPTIONS_INVALID
526
- <a id="FST_ERR_LISTEN_OPTIONS_INVALID"></a>
220
+ Below is a table with all the error codes that Fastify uses.
221
+
222
+ | Code | Description | How to solve | Discussion |
223
+ |------|-------------|--------------|------------|
224
+ | <a id="fst_err_not_found">FST_ERR_NOT_FOUND</a> | 404 Not Found | - | [#1168](https://github.com/fastify/fastify/pull/1168) |
225
+ | <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) |
226
+ | <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) |
227
+ | <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) |
228
+ | <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) |
229
+ | <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) |
230
+ | <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) |
231
+ | <a id="fst_err_version_constraint_not_str">FST_ERR_VERSION_CONSTRAINT_NOT_STR</a> | Version constraint wrongly specified. | Version constraint should be a string. | [#4554](https://github.com/fastify/fastify/pull/4554) |
232
+ | <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) |
233
+ | <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) |
234
+ | <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) |
235
+ | <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) |
236
+ | <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) |
237
+ | <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) |
238
+ | <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) |
239
+ | <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) |
240
+ | <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) |
241
+ | <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) |
242
+ | <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) |
243
+ | <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) |
244
+ | <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) |
245
+ | <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) |
246
+ | <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) |
247
+ | <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) |
248
+ | <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) |
249
+ | <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) |
250
+ | <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) |
251
+ | <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) |
252
+ | <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) |
253
+ | <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) |
254
+ | <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) |
255
+ | <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) |
256
+ | <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) |
257
+ | <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) |
258
+ | <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) |
259
+ | <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) |
260
+ | <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) |
261
+ | <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) |
262
+ | <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) |
263
+ | <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) |
264
+ | <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) |
265
+ | <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) |
266
+ | <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) |
267
+ | <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) |
268
+ | <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) |
269
+ | <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) |
270
+ | <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) |
271
+ | <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) |
272
+ | <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) |
273
+ | <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) |
274
+ | <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) |
275
+ | <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) |
276
+ | <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) |
277
+ | <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) |
278
+ | <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) |
279
+ | <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) |
280
+ | <a id="fst_err_default_route_invalid_type">FST_ERR_DEFAULT_ROUTE_INVALID_TYPE</a> | The `defaultRoute` type should be a function. | Use a function for the `defaultRoute`. | [#2733](https://github.com/fastify/fastify/pull/2733) |
281
+ | <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) |
282
+ | <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) |
283
+ | <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) |
284
+ | <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) |
285
+ | <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) |
286
+ | <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) |
287
+ | <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) |
288
+ | <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) |
289
+ | <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) |
290
+ | <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) |
291
+ | <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) |
292
+ | <a id="fst_err_reopened_server">FST_ERR_REOPENED_SERVER</a> | Fastify is already listening. | - | [#2415](https://github.com/fastify/fastify/pull/2415) |
293
+ | <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) |
294
+ | <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) |
295
+ | <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) |
296
+ | <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) |
297
+ | <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) |
298
+ | <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) |
299
+ | <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) |
300
+ | <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) |
301
+ | <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) |
527
302
 
528
- Invalid listen options.
@@ -130,6 +130,10 @@ fastify.addHook('preValidation', async (request, reply) => {
130
130
  ```
131
131
 
132
132
  ### preHandler
133
+
134
+ The `preHandler` hook allows you to specify a function that is executed before
135
+ a routes's handler.
136
+
133
137
  ```js
134
138
  fastify.addHook('preHandler', (request, reply, done) => {
135
139
  // some code
@@ -346,9 +350,11 @@ fastify.addHook('onRequest', (request, reply, done) => {
346
350
 
347
351
  // Works with async functions too
348
352
  fastify.addHook('preHandler', async (request, reply) => {
349
- await something()
350
- reply.send({ hello: 'world' })
353
+ setTimeout(() => {
354
+ reply.send({ hello: 'from prehandler' })
355
+ })
351
356
  return reply // mandatory, so the request is not executed further
357
+ // Commenting the line above will allow the hooks to continue and fail with FST_ERR_REP_ALREADY_SENT
352
358
  })
353
359
  ```
354
360
 
@@ -69,3 +69,5 @@ This table of contents is in alphabetical order.
69
69
  + [Validation and Serialization](./Validation-and-Serialization.md): Details
70
70
  Fastify's support for validating incoming data and how Fastify serializes data
71
71
  for responses.
72
+ + [Warnings](./Warnings.md): Details the warnings Fastify emits and how to
73
+ solve them.