UNPKG

5.52 kBJavaScriptView Raw
1'use strict'
2
3const createError = require('fastify-error')
4const codes = {
5 /**
6 * Basic
7 */
8 FST_ERR_NOT_FOUND: createError(
9 'FST_ERR_NOT_FOUND',
10 'Not Found',
11 404
12 ),
13
14 /**
15 * ContentTypeParser
16 */
17 FST_ERR_CTP_ALREADY_PRESENT: createError(
18 'FST_ERR_CTP_ALREADY_PRESENT',
19 "Content type parser '%s' already present."
20 ),
21 FST_ERR_CTP_INVALID_TYPE: createError(
22 'FST_ERR_CTP_INVALID_TYPE',
23 'The content type should be a string',
24 500,
25 TypeError
26 ),
27 FST_ERR_CTP_EMPTY_TYPE: createError(
28 'FST_ERR_CTP_EMPTY_TYPE',
29 'The content type cannot be an empty string',
30 500,
31 TypeError
32 ),
33 FST_ERR_CTP_INVALID_HANDLER: createError(
34 'FST_ERR_CTP_INVALID_HANDLER',
35 'The content type handler should be a function',
36 500,
37 TypeError
38 ),
39 FST_ERR_CTP_INVALID_PARSE_TYPE: createError(
40 'FST_ERR_CTP_INVALID_PARSE_TYPE',
41 "The body parser can only parse your data as 'string' or 'buffer', you asked '%s' which is not supported.",
42 500,
43 TypeError
44 ),
45 FST_ERR_CTP_BODY_TOO_LARGE: createError(
46 'FST_ERR_CTP_BODY_TOO_LARGE',
47 'Request body is too large',
48 413,
49 RangeError
50 ),
51 FST_ERR_CTP_INVALID_MEDIA_TYPE: createError(
52 'FST_ERR_CTP_INVALID_MEDIA_TYPE',
53 'Unsupported Media Type: %s',
54 415
55 ),
56 FST_ERR_CTP_INVALID_CONTENT_LENGTH: createError(
57 'FST_ERR_CTP_INVALID_CONTENT_LENGTH',
58 'Request body size did not match Content-Length',
59 400,
60 RangeError
61 ),
62 FST_ERR_CTP_EMPTY_JSON_BODY: createError(
63 'FST_ERR_CTP_EMPTY_JSON_BODY',
64 "Body cannot be empty when content-type is set to 'application/json'",
65 400
66 ),
67
68 /**
69 * decorate
70 */
71 FST_ERR_DEC_ALREADY_PRESENT: createError(
72 'FST_ERR_DEC_ALREADY_PRESENT',
73 "The decorator '%s' has already been added!"
74 ),
75 FST_ERR_DEC_MISSING_DEPENDENCY: createError(
76 'FST_ERR_DEC_MISSING_DEPENDENCY',
77 "The decorator is missing dependency '%s'."
78 ),
79 FST_ERR_DEC_AFTER_START: createError(
80 'FST_ERR_DEC_AFTER_START',
81 "The decorator '%s' has been added after start!"
82 ),
83
84 /**
85 * hooks
86 */
87 FST_ERR_HOOK_INVALID_TYPE: createError(
88 'FST_ERR_HOOK_INVALID_TYPE',
89 'The hook name must be a string',
90 500,
91 TypeError
92 ),
93 FST_ERR_HOOK_INVALID_HANDLER: createError(
94 'FST_ERR_HOOK_INVALID_HANDLER',
95 'The hook callback must be a function',
96 500,
97 TypeError
98 ),
99
100 /**
101 * Middlewares
102 */
103 FST_ERR_MISSING_MIDDLEWARE: createError(
104 'FST_ERR_MISSING_MIDDLEWARE',
105 'You must register a plugin for handling middlewares, visit fastify.io/docs/latest/Middleware/ for more info.',
106 500
107 ),
108
109 /**
110 * logger
111 */
112 FST_ERR_LOG_INVALID_DESTINATION: createError(
113 'FST_ERR_LOG_INVALID_DESTINATION',
114 'Cannot specify both logger.stream and logger.file options'
115 ),
116
117 /**
118 * reply
119 */
120 FST_ERR_REP_INVALID_PAYLOAD_TYPE: createError(
121 'FST_ERR_REP_INVALID_PAYLOAD_TYPE',
122 "Attempted to send payload of invalid type '%s'. Expected a string or Buffer.",
123 500,
124 TypeError
125 ),
126 FST_ERR_REP_ALREADY_SENT: createError(
127 'FST_ERR_REP_ALREADY_SENT',
128 'Reply was already sent.'
129 ),
130 FST_ERR_REP_SENT_VALUE: createError(
131 'FST_ERR_REP_SENT_VALUE',
132 'The only possible value for reply.sent is true.'
133 ),
134 FST_ERR_SEND_INSIDE_ONERR: createError(
135 'FST_ERR_SEND_INSIDE_ONERR',
136 'You cannot use `send` inside the `onError` hook'
137 ),
138 FST_ERR_SEND_UNDEFINED_ERR: createError(
139 'FST_ERR_SEND_UNDEFINED_ERR',
140 'Undefined error has occured'
141 ),
142 FST_ERR_BAD_STATUS_CODE: createError(
143 'FST_ERR_BAD_STATUS_CODE',
144 'Called reply with an invalid status code: %s'
145 ),
146
147 /**
148 * schemas
149 */
150 FST_ERR_SCH_MISSING_ID: createError(
151 'FST_ERR_SCH_MISSING_ID',
152 'Missing schema $id property'
153 ),
154 FST_ERR_SCH_ALREADY_PRESENT: createError(
155 'FST_ERR_SCH_ALREADY_PRESENT',
156 "Schema with id '%s' already declared!"
157 ),
158 FST_ERR_SCH_DUPLICATE: createError(
159 'FST_ERR_SCH_DUPLICATE',
160 "Schema with '%s' already present!"
161 ),
162 FST_ERR_SCH_VALIDATION_BUILD: createError(
163 'FST_ERR_SCH_VALIDATION_BUILD',
164 'Failed building the validation schema for %s: %s, due to error %s'
165 ),
166 FST_ERR_SCH_SERIALIZATION_BUILD: createError(
167 'FST_ERR_SCH_SERIALIZATION_BUILD',
168 'Failed building the serialization schema for %s: %s, due to error %s'
169 ),
170
171 /**
172 * wrapThenable
173 */
174 FST_ERR_PROMISE_NOT_FULLFILLED: createError(
175 'FST_ERR_PROMISE_NOT_FULLFILLED',
176 "Promise may not be fulfilled with 'undefined' when statusCode is not 204"
177 ),
178
179 /**
180 * http2
181 */
182 FST_ERR_HTTP2_INVALID_VERSION: createError(
183 'FST_ERR_HTTP2_INVALID_VERSION',
184 'HTTP2 is available only from node >= 8.8.1'
185 ),
186
187 /**
188 * initialConfig
189 */
190 FST_ERR_INIT_OPTS_INVALID: createError(
191 'FST_ERR_INIT_OPTS_INVALID',
192 "Invalid initialization options: '%s'"
193 ),
194
195 /**
196 * router
197 */
198 FST_ERR_BAD_URL: createError(
199 'FST_ERR_BAD_URL',
200 "'%s' is not a valid url component",
201 400
202 ),
203
204 /**
205 * again listen when close server
206 */
207 FST_ERR_REOPENED_CLOSE_SERVER: createError(
208 'FST_ERR_REOPENED_CLOSE_SERVER',
209 'Fastify has already been closed and cannot be reopened'
210 ),
211 FST_ERR_REOPENED_SERVER: createError(
212 'FST_ERR_REOPENED_SERVER',
213 'Fastify is already listening'
214 ),
215
216 /**
217 * plugin
218 */
219 FST_ERR_PLUGIN_VERSION_MISMATCH: createError(
220 'FST_ERR_PLUGIN_VERSION_MISMATCH',
221 "fastify-plugin: %s - expected '%s' fastify version, '%s' is installed"
222 )
223}
224
225module.exports = codes