UNPKG

4.37 kBMarkdownView Raw
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
9Uncaught 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
11Fastify 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
13Note that Fastify doesn't catch uncaught errors within callback based routes for you, so any uncaught errors will result in a crash.
14If 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
22The 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
27The content type should be a string.
28
29<a name="FST_ERR_CTP_EMPTY_TYPE"></a>
30#### FST_ERR_CTP_EMPTY_TYPE
31
32The content type cannot be an empty string.
33
34<a name="FST_ERR_CTP_INVALID_HANDLER"></a>
35#### FST_ERR_CTP_INVALID_HANDLER
36
37An 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
42The 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
47Request 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
52Received 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
57Request body size did not match Content-Length.
58
59<a name="FST_ERR_DEC_ALREADY_PRESENT"></a>
60#### FST_ERR_DEC_ALREADY_PRESENT
61
62A 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
67The 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
72The hook name must be a string.
73
74<a name="FST_ERR_HOOK_INVALID_HANDLER"></a>
75#### FST_ERR_HOOK_INVALID_HANDLER
76
77The hook callback must be a function.
78
79<a name="FST_ERR_LOG_INVALID_DESTINATION"></a>
80#### FST_ERR_LOG_INVALID_DESTINATION
81
82Logger 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
87A response was already sent.
88
89<a id="FST_ERR_SEND_INSIDE_ONERR"></a>
90#### FST_ERR_SEND_INSIDE_ONERR
91
92You 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
97Reply 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
102The schema provided does not have `$id` property.
103
104<a name="FST_ERR_SCH_ALREADY_PRESENT"></a>
105#### FST_ERR_SCH_ALREADY_PRESENT
106
107A schema with the same `$id` already exists.
108
109<a name="FST_ERR_SCH_NOT_PRESENT"></a>
110#### FST_ERR_SCH_NOT_PRESENT
111
112No schema with the provided `$id` exists.
113
114<a name="FST_ERR_PROMISE_NOT_FULLFILLED"></a>
115#### FST_ERR_PROMISE_NOT_FULLFILLED
116
117Promise may not be fulfilled with 'undefined' when statusCode is not 204.