UNPKG

4.69 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 sensibly, 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 behaviour, 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_BAD_URL"></a>
20#### FST_ERR_BAD_URL
21
22The router received an invalid url.
23
24<a name="FST_ERR_CTP_ALREADY_PRESENT"></a>
25#### FST_ERR_CTP_ALREADY_PRESENT
26
27The parser for this content type was already registered.
28
29<a name="FST_ERR_CTP_INVALID_TYPE"></a>
30#### FST_ERR_CTP_INVALID_TYPE
31
32The `Content-Type` should be a string.
33
34<a name="FST_ERR_CTP_EMPTY_TYPE"></a>
35#### FST_ERR_CTP_EMPTY_TYPE
36
37The content type cannot be an empty string.
38
39<a name="FST_ERR_CTP_INVALID_HANDLER"></a>
40#### FST_ERR_CTP_INVALID_HANDLER
41
42An invalid handler was passed for the content type.
43
44<a name="FST_ERR_CTP_INVALID_PARSE_TYPE"></a>
45#### FST_ERR_CTP_INVALID_PARSE_TYPE
46
47The provided parse type is not supported. Accepted values are `string` or `buffer`.
48
49<a name="FST_ERR_CTP_BODY_TOO_LARGE"></a>
50#### FST_ERR_CTP_BODY_TOO_LARGE
51
52The request body is larger than the provided limit.
53
54<a name="FST_ERR_CTP_INVALID_MEDIA_TYPE"></a>
55#### FST_ERR_CTP_INVALID_MEDIA_TYPE
56
57The received media type is not supported (i.e. there is no suitable `Content-Type` parser for it).
58
59<a name="FST_ERR_CTP_INVALID_CONTENT_LENGTH"></a>
60#### FST_ERR_CTP_INVALID_CONTENT_LENGTH
61
62Request body size did not match Content-Length.
63
64<a name="FST_ERR_DEC_ALREADY_PRESENT"></a>
65#### FST_ERR_DEC_ALREADY_PRESENT
66
67A decorator with the same name is already registered.
68
69<a name="FST_ERR_DEC_MISSING_DEPENDENCY"></a>
70#### FST_ERR_DEC_MISSING_DEPENDENCY
71
72The decorator cannot be registered due to a missing dependency.
73
74<a name="FST_ERR_HOOK_INVALID_TYPE"></a>
75#### FST_ERR_HOOK_INVALID_TYPE
76
77The hook name must be a string.
78
79<a name="FST_ERR_HOOK_INVALID_HANDLER"></a>
80#### FST_ERR_HOOK_INVALID_HANDLER
81
82The hook callback must be a function.
83
84<a name="FST_ERR_LOG_INVALID_DESTINATION"></a>
85#### FST_ERR_LOG_INVALID_DESTINATION
86
87The logger accepts either a `'stream'` or a `'file'` as the destination.
88
89<a id="FST_ERR_REP_ALREADY_SENT"></a>
90### FST_ERR_REP_ALREADY_SENT
91
92A response was already sent.
93
94<a id="FST_ERR_SEND_INSIDE_ONERR"></a>
95#### FST_ERR_SEND_INSIDE_ONERR
96
97You cannot use `send` inside the `onError` hook.
98
99<a name="FST_ERR_REP_INVALID_PAYLOAD_TYPE"></a>
100#### FST_ERR_REP_INVALID_PAYLOAD_TYPE
101
102Reply payload can either be a `string` or a `Buffer`.
103
104<a name="FST_ERR_SCH_MISSING_ID"></a>
105#### FST_ERR_SCH_MISSING_ID
106
107The schema provided does not have `$id` property.
108
109<a name="FST_ERR_SCH_ALREADY_PRESENT"></a>
110#### FST_ERR_SCH_ALREADY_PRESENT
111
112A schema with the same `$id` already exists.
113
114<a name="FST_ERR_SCH_NOT_PRESENT"></a>
115#### FST_ERR_SCH_NOT_PRESENT
116
117No schema with the provided `$id` exists.
118
119<a name="FST_ERR_SCH_BUILD"></a>
120#### FST_ERR_SCH_BUILD
121
122The JSON schema provided to one route is not valid.
123
124<a name="FST_ERR_PROMISE_NOT_FULLFILLED"></a>
125#### FST_ERR_PROMISE_NOT_FULLFILLED
126
127A promise may not be fulfilled with 'undefined' when statusCode is not 204.
128
129<a name="FST_ERR_SEND_UNDEFINED_ERR"></a>
130#### FST_ERR_SEND_UNDEFINED_ERR
131
132Undefined error has occured.