1 | <h1 align="center">Fastify</h1>
|
2 |
|
3 | <a id="errors"></a>
|
4 | ## Errors
|
5 |
|
6 | <a name="error-handling"></a>
|
7 | ### Error Handling
|
8 |
|
9 | Uncaught errors are likely to cause memory leaks, file descriptor leaks and other major production issues. [Domains](https://nodejs.org/en/docs/guides/domain-postmortem/) were introduced to try fixing this issue, but they did not. Given the fact that it is not possible to process all uncaught errors in a sensible way, the best way to deal with them at the moment is to [crash](https://nodejs.org/api/process.html#process_warning_using_uncaughtexception_correctly). In case of promises, make sure to [handle](https://nodejs.org/dist/latest-v8.x/docs/api/deprecations.html#deprecations_dep0018_unhandled_promise_rejections) errors [correctly](https://github.com/mcollina/make-promises-safe).
|
10 |
|
11 | Fastify follows an all-or-nothing approach and aims to be lean and optimal as much as possible. Thus, the developer is responsible for making sure that the errors are handled properly. Most of the errors are usually a result of unexpected input data, so we recommend specifying a [JSON.schema validation](https://github.com/fastify/fastify/blob/master/docs/Validation-and-Serialization.md) for your input data.
|
12 |
|
13 | Note that Fastify doesn't catch uncaught errors within callback based routes for you, so any uncaught errors will result in a crash.
|
14 | If routes are declared as `async` though - the error will safely be caught by the promise and routed to the default error handler of Fastify for a generic `Internal Server Error` response. For customizing this behavior, you should use [setErrorHandler](https://github.com/fastify/fastify/blob/master/docs/Server.md#seterrorhandler).
|
15 |
|
16 | <a name="fastify-error-codes"></a>
|
17 | ### Fastify Error Codes
|
18 |
|
19 | <a name="FST_ERR_CTP_ALREADY_PRESENT"></a>
|
20 | #### FST_ERR_CTP_ALREADY_PRESENT
|
21 |
|
22 | The parser for this content type was already registered.
|
23 |
|
24 | <a name="FST_ERR_CTP_INVALID_TYPE"></a>
|
25 | #### FST_ERR_CTP_INVALID_TYPE
|
26 |
|
27 | The content type should be a string.
|
28 |
|
29 | <a name="FST_ERR_CTP_EMPTY_TYPE"></a>
|
30 | #### FST_ERR_CTP_EMPTY_TYPE
|
31 |
|
32 | The content type cannot be an empty string.
|
33 |
|
34 | <a name="FST_ERR_CTP_INVALID_HANDLER"></a>
|
35 | #### FST_ERR_CTP_INVALID_HANDLER
|
36 |
|
37 | An invalid handler was passed for the content type.
|
38 |
|
39 | <a name="FST_ERR_CTP_INVALID_PARSE_TYPE"></a>
|
40 | #### FST_ERR_CTP_INVALID_PARSE_TYPE
|
41 |
|
42 | The provided parse type is not supported. Accepted values are `string` or `buffer`.
|
43 |
|
44 | <a name="FST_ERR_CTP_BODY_TOO_LARGE"></a>
|
45 | #### FST_ERR_CTP_BODY_TOO_LARGE
|
46 |
|
47 | Request body is larger than the provided limit.
|
48 |
|
49 | <a name="FST_ERR_CTP_INVALID_MEDIA_TYPE"></a>
|
50 | #### FST_ERR_CTP_INVALID_MEDIA_TYPE
|
51 |
|
52 | Received media type is not supported (i.e. there is no suitable content-type parser for it).
|
53 |
|
54 | <a name="FST_ERR_CTP_INVALID_CONTENT_LENGTH"></a>
|
55 | #### FST_ERR_CTP_INVALID_CONTENT_LENGTH
|
56 |
|
57 | Request body size did not match Content-Length.
|
58 |
|
59 | <a name="FST_ERR_DEC_ALREADY_PRESENT"></a>
|
60 | #### FST_ERR_DEC_ALREADY_PRESENT
|
61 |
|
62 | A decorator with the same name is already registered.
|
63 |
|
64 | <a name="FST_ERR_DEC_MISSING_DEPENDENCY"></a>
|
65 | #### FST_ERR_DEC_MISSING_DEPENDENCY
|
66 |
|
67 | The decorator cannot be registered due to a missing dependency.
|
68 |
|
69 | <a name="FST_ERR_HOOK_INVALID_TYPE"></a>
|
70 | #### FST_ERR_HOOK_INVALID_TYPE
|
71 |
|
72 | The hook name must be a string.
|
73 |
|
74 | <a name="FST_ERR_HOOK_INVALID_HANDLER"></a>
|
75 | #### FST_ERR_HOOK_INVALID_HANDLER
|
76 |
|
77 | The hook callback must be a function.
|
78 |
|
79 | <a name="FST_ERR_LOG_INVALID_DESTINATION"></a>
|
80 | #### FST_ERR_LOG_INVALID_DESTINATION
|
81 |
|
82 | Logger acceptes either a `'stream'` or a `'file'` as the destination.
|
83 |
|
84 | <a id="FST_ERR_REP_ALREADY_SENT"></a>
|
85 | ### FST_ERR_REP_ALREADY_SENT
|
86 |
|
87 | A response was already sent.
|
88 |
|
89 | <a id="FST_ERR_SEND_INSIDE_ONERR"></a>
|
90 | #### FST_ERR_SEND_INSIDE_ONERR
|
91 |
|
92 | You cannot use `send` inside the `onError` hook.
|
93 |
|
94 | <a name="FST_ERR_REP_INVALID_PAYLOAD_TYPE"></a>
|
95 | #### FST_ERR_REP_INVALID_PAYLOAD_TYPE
|
96 |
|
97 | Reply payload can either be a `string` or a `Buffer`.
|
98 |
|
99 | <a name="FST_ERR_SCH_MISSING_ID"></a>
|
100 | #### FST_ERR_SCH_MISSING_ID
|
101 |
|
102 | The schema provided does not have `$id` property.
|
103 |
|
104 | <a name="FST_ERR_SCH_ALREADY_PRESENT"></a>
|
105 | #### FST_ERR_SCH_ALREADY_PRESENT
|
106 |
|
107 | A schema with the same `$id` already exists.
|
108 |
|
109 | <a name="FST_ERR_SCH_NOT_PRESENT"></a>
|
110 | #### FST_ERR_SCH_NOT_PRESENT
|
111 |
|
112 | No schema with the provided `$id` exists.
|
113 |
|
114 | <a name="FST_ERR_PROMISE_NOT_FULLFILLED"></a>
|
115 | #### FST_ERR_PROMISE_NOT_FULLFILLED
|
116 |
|
117 | Promise may not be fulfilled with 'undefined' when statusCode is not 204.
|