strong-tie/inbound-calls
0
1'use strict'2 3const createError = require('@fastify/error')4 5const codes = {6 /**7 * Basic8 */9 FST_ERR_NOT_FOUND: createError(10 'FST_ERR_NOT_FOUND',11 'Not Found',12 40413 ),14 FST_ERR_OPTIONS_NOT_OBJ: createError(15 'FST_ERR_OPTIONS_NOT_OBJ',16 'Options must be an object',17 500,18 TypeError19 ),20 FST_ERR_QSP_NOT_FN: createError(21 'FST_ERR_QSP_NOT_FN',22 "querystringParser option should be a function, instead got '%s'",23 500,24 TypeError25 ),26 FST_ERR_SCHEMA_CONTROLLER_BUCKET_OPT_NOT_FN: createError(27 'FST_ERR_SCHEMA_CONTROLLER_BUCKET_OPT_NOT_FN',28 "schemaController.bucket option should be a function, instead got '%s'",29 500,30 TypeError31 ),32 FST_ERR_SCHEMA_ERROR_FORMATTER_NOT_FN: createError(33 'FST_ERR_SCHEMA_ERROR_FORMATTER_NOT_FN',34 "schemaErrorFormatter option should be a non async function. Instead got '%s'.",35 500,36 TypeError37 ),38 FST_ERR_AJV_CUSTOM_OPTIONS_OPT_NOT_OBJ: createError(39 'FST_ERR_AJV_CUSTOM_OPTIONS_OPT_NOT_OBJ',40 "ajv.customOptions option should be an object, instead got '%s'",41 500,42 TypeError43 ),44 FST_ERR_AJV_CUSTOM_OPTIONS_OPT_NOT_ARR: createError(45 'FST_ERR_AJV_CUSTOM_OPTIONS_OPT_NOT_ARR',46 "ajv.plugins option should be an array, instead got '%s'",47 500,48 TypeError49 ),50 FST_ERR_VALIDATION: createError(51 'FST_ERR_VALIDATION',52 '%s',53 40054 ),55 FST_ERR_LISTEN_OPTIONS_INVALID: createError(56 'FST_ERR_LISTEN_OPTIONS_INVALID',57 "Invalid listen options: '%s'",58 500,59 TypeError60 ),61 FST_ERR_ERROR_HANDLER_NOT_FN: createError(62 'FST_ERR_ERROR_HANDLER_NOT_FN',63 'Error Handler must be a function',64 500,65 TypeError66 ),67 68 /**69 * ContentTypeParser70 */71 FST_ERR_CTP_ALREADY_PRESENT: createError(72 'FST_ERR_CTP_ALREADY_PRESENT',73 "Content type parser '%s' already present."74 ),75 FST_ERR_CTP_INVALID_TYPE: createError(76 'FST_ERR_CTP_INVALID_TYPE',77 'The content type should be a string or a RegExp',78 500,79 TypeError80 ),81 FST_ERR_CTP_EMPTY_TYPE: createError(82 'FST_ERR_CTP_EMPTY_TYPE',83 'The content type cannot be an empty string',84 500,85 TypeError86 ),87 FST_ERR_CTP_INVALID_HANDLER: createError(88 'FST_ERR_CTP_INVALID_HANDLER',89 'The content type handler should be a function',90 500,91 TypeError92 ),93 FST_ERR_CTP_INVALID_PARSE_TYPE: createError(94 'FST_ERR_CTP_INVALID_PARSE_TYPE',95 "The body parser can only parse your data as 'string' or 'buffer', you asked '%s' which is not supported.",96 500,97 TypeError98 ),99 FST_ERR_CTP_BODY_TOO_LARGE: createError(100 'FST_ERR_CTP_BODY_TOO_LARGE',101 'Request body is too large',102 413,103 RangeError104 ),105 FST_ERR_CTP_INVALID_MEDIA_TYPE: createError(106 'FST_ERR_CTP_INVALID_MEDIA_TYPE',107 'Unsupported Media Type: %s',108 415109 ),110 FST_ERR_CTP_INVALID_CONTENT_LENGTH: createError(111 'FST_ERR_CTP_INVALID_CONTENT_LENGTH',112 'Request body size did not match Content-Length',113 400,114 RangeError115 ),116 FST_ERR_CTP_EMPTY_JSON_BODY: createError(117 'FST_ERR_CTP_EMPTY_JSON_BODY',118 "Body cannot be empty when content-type is set to 'application/json'",119 400120 ),121 FST_ERR_CTP_INSTANCE_ALREADY_STARTED: createError(122 'FST_ERR_CTP_INSTANCE_ALREADY_STARTED',123 'Cannot call "%s" when fastify instance is already started!',124 400125 ),126 127 /**128 * decorate129 */130 FST_ERR_DEC_ALREADY_PRESENT: createError(131 'FST_ERR_DEC_ALREADY_PRESENT',132 "The decorator '%s' has already been added!"133 ),134 FST_ERR_DEC_DEPENDENCY_INVALID_TYPE: createError(135 'FST_ERR_DEC_DEPENDENCY_INVALID_TYPE',136 "The dependencies of decorator '%s' must be of type Array.",137 500,138 TypeError139 ),140 FST_ERR_DEC_MISSING_DEPENDENCY: createError(141 'FST_ERR_DEC_MISSING_DEPENDENCY',142 "The decorator is missing dependency '%s'."143 ),144 FST_ERR_DEC_AFTER_START: createError(145 'FST_ERR_DEC_AFTER_START',146 "The decorator '%s' has been added after start!"147 ),148 FST_ERR_DEC_REFERENCE_TYPE: createError(149 'FST_ERR_DEC_REFERENCE_TYPE',150 "The decorator '%s' of type '%s' is a reference type. Use the { getter, setter } interface instead."151 ),152 153 /**154 * hooks155 */156 FST_ERR_HOOK_INVALID_TYPE: createError(157 'FST_ERR_HOOK_INVALID_TYPE',158 'The hook name must be a string',159 500,160 TypeError161 ),162 FST_ERR_HOOK_INVALID_HANDLER: createError(163 'FST_ERR_HOOK_INVALID_HANDLER',164 '%s hook should be a function, instead got %s',165 500,166 TypeError167 ),168 FST_ERR_HOOK_INVALID_ASYNC_HANDLER: createError(169 'FST_ERR_HOOK_INVALID_ASYNC_HANDLER',170 'Async function has too many arguments. Async hooks should not use the \'done\' argument.',171 500,172 TypeError173 ),174 FST_ERR_HOOK_NOT_SUPPORTED: createError(175 'FST_ERR_HOOK_NOT_SUPPORTED',176 '%s hook not supported!',177 500,178 TypeError179 ),180 181 /**182 * Middlewares183 */184 FST_ERR_MISSING_MIDDLEWARE: createError(185 'FST_ERR_MISSING_MIDDLEWARE',186 'You must register a plugin for handling middlewares, visit fastify.dev/docs/latest/Reference/Middleware/ for more info.',187 500188 ),189 190 FST_ERR_HOOK_TIMEOUT: createError(191 'FST_ERR_HOOK_TIMEOUT',192 "A callback for '%s' hook%s timed out. You may have forgotten to call 'done' function or to resolve a Promise"193 ),194 195 /**196 * logger197 */198 FST_ERR_LOG_INVALID_DESTINATION: createError(199 'FST_ERR_LOG_INVALID_DESTINATION',200 'Cannot specify both logger.stream and logger.file options'201 ),202 203 FST_ERR_LOG_INVALID_LOGGER: createError(204 'FST_ERR_LOG_INVALID_LOGGER',205 "Invalid logger object provided. The logger instance should have these functions(s): '%s'.",206 500,207 TypeError208 ),209 210 FST_ERR_LOG_INVALID_LOGGER_INSTANCE: createError(211 'FST_ERR_LOG_INVALID_LOGGER_INSTANCE',212 'loggerInstance only accepts a logger instance.',213 500,214 TypeError215 ),216 217 FST_ERR_LOG_INVALID_LOGGER_CONFIG: createError(218 'FST_ERR_LOG_INVALID_LOGGER_CONFIG',219 'logger options only accepts a configuration object.',220 500,221 TypeError222 ),223 224 FST_ERR_LOG_LOGGER_AND_LOGGER_INSTANCE_PROVIDED: createError(225 'FST_ERR_LOG_LOGGER_AND_LOGGER_INSTANCE_PROVIDED',226 'You cannot provide both logger and loggerInstance. Please provide only one.',227 500,228 TypeError229 ),230 231 /**232 * reply233 */234 FST_ERR_REP_INVALID_PAYLOAD_TYPE: createError(235 'FST_ERR_REP_INVALID_PAYLOAD_TYPE',236 "Attempted to send payload of invalid type '%s'. Expected a string or Buffer.",237 500,238 TypeError239 ),240 FST_ERR_REP_RESPONSE_BODY_CONSUMED: createError(241 'FST_ERR_REP_RESPONSE_BODY_CONSUMED',242 'Response.body is already consumed.'243 ),244 FST_ERR_REP_READABLE_STREAM_LOCKED: createError(245 'FST_ERR_REP_READABLE_STREAM_LOCKED',246 'ReadableStream was locked. You should call releaseLock() method on reader before sending.'247 ),248 FST_ERR_REP_ALREADY_SENT: createError(249 'FST_ERR_REP_ALREADY_SENT',250 'Reply was already sent, did you forget to "return reply" in "%s" (%s)?'251 ),252 FST_ERR_REP_SENT_VALUE: createError(253 'FST_ERR_REP_SENT_VALUE',254 'The only possible value for reply.sent is true.',255 500,256 TypeError257 ),258 FST_ERR_SEND_INSIDE_ONERR: createError(259 'FST_ERR_SEND_INSIDE_ONERR',260 'You cannot use `send` inside the `onError` hook'261 ),262 FST_ERR_SEND_UNDEFINED_ERR: createError(263 'FST_ERR_SEND_UNDEFINED_ERR',264 'Undefined error has occurred'265 ),266 FST_ERR_BAD_STATUS_CODE: createError(267 'FST_ERR_BAD_STATUS_CODE',268 'Called reply with an invalid status code: %s'269 ),270 FST_ERR_BAD_TRAILER_NAME: createError(271 'FST_ERR_BAD_TRAILER_NAME',272 'Called reply.trailer with an invalid header name: %s'273 ),274 FST_ERR_BAD_TRAILER_VALUE: createError(275 'FST_ERR_BAD_TRAILER_VALUE',276 "Called reply.trailer('%s', fn) with an invalid type: %s. Expected a function."277 ),278 FST_ERR_FAILED_ERROR_SERIALIZATION: createError(279 'FST_ERR_FAILED_ERROR_SERIALIZATION',280 'Failed to serialize an error. Error: %s. Original error: %s'281 ),282 FST_ERR_MISSING_SERIALIZATION_FN: createError(283 'FST_ERR_MISSING_SERIALIZATION_FN',284 'Missing serialization function. Key "%s"'285 ),286 FST_ERR_MISSING_CONTENTTYPE_SERIALIZATION_FN: createError(287 'FST_ERR_MISSING_CONTENTTYPE_SERIALIZATION_FN',288 'Missing serialization function. Key "%s:%s"'289 ),290 FST_ERR_REQ_INVALID_VALIDATION_INVOCATION: createError(291 'FST_ERR_REQ_INVALID_VALIDATION_INVOCATION',292 'Invalid validation invocation. Missing validation function for HTTP part "%s" nor schema provided.'293 ),294 295 /**296 * schemas297 */298 FST_ERR_SCH_MISSING_ID: createError(299 'FST_ERR_SCH_MISSING_ID',300 'Missing schema $id property'301 ),302 FST_ERR_SCH_ALREADY_PRESENT: createError(303 'FST_ERR_SCH_ALREADY_PRESENT',304 "Schema with id '%s' already declared!"305 ),306 FST_ERR_SCH_CONTENT_MISSING_SCHEMA: createError(307 'FST_ERR_SCH_CONTENT_MISSING_SCHEMA',308 "Schema is missing for the content type '%s'"309 ),310 FST_ERR_SCH_DUPLICATE: createError(311 'FST_ERR_SCH_DUPLICATE',312 "Schema with '%s' already present!"313 ),314 FST_ERR_SCH_VALIDATION_BUILD: createError(315 'FST_ERR_SCH_VALIDATION_BUILD',316 'Failed building the validation schema for %s: %s, due to error %s'317 ),318 FST_ERR_SCH_SERIALIZATION_BUILD: createError(319 'FST_ERR_SCH_SERIALIZATION_BUILD',320 'Failed building the serialization schema for %s: %s, due to error %s'321 ),322 FST_ERR_SCH_RESPONSE_SCHEMA_NOT_NESTED_2XX: createError(323 'FST_ERR_SCH_RESPONSE_SCHEMA_NOT_NESTED_2XX',324 'response schemas should be nested under a valid status code, e.g { 2xx: { type: "object" } }'325 ),326 327 /**328 * http2329 */330 FST_ERR_HTTP2_INVALID_VERSION: createError(331 'FST_ERR_HTTP2_INVALID_VERSION',332 'HTTP2 is available only from node >= 8.8.1'333 ),334 335 /**336 * initialConfig337 */338 FST_ERR_INIT_OPTS_INVALID: createError(339 'FST_ERR_INIT_OPTS_INVALID',340 "Invalid initialization options: '%s'"341 ),342 FST_ERR_FORCE_CLOSE_CONNECTIONS_IDLE_NOT_AVAILABLE: createError(343 'FST_ERR_FORCE_CLOSE_CONNECTIONS_IDLE_NOT_AVAILABLE',344 "Cannot set forceCloseConnections to 'idle' as your HTTP server does not support closeIdleConnections method"345 ),346 347 /**348 * router349 */350 FST_ERR_DUPLICATED_ROUTE: createError(351 'FST_ERR_DUPLICATED_ROUTE',352 "Method '%s' already declared for route '%s'"353 ),354 FST_ERR_BAD_URL: createError(355 'FST_ERR_BAD_URL',356 "'%s' is not a valid url component",357 400,358 URIError359 ),360 FST_ERR_ASYNC_CONSTRAINT: createError(361 'FST_ERR_ASYNC_CONSTRAINT',362 'Unexpected error from async constraint',363 500364 ),365 FST_ERR_INVALID_URL: createError(366 'FST_ERR_INVALID_URL',367 "URL must be a string. Received '%s'",368 400,369 TypeError370 ),371 FST_ERR_ROUTE_OPTIONS_NOT_OBJ: createError(372 'FST_ERR_ROUTE_OPTIONS_NOT_OBJ',373 'Options for "%s:%s" route must be an object',374 500,375 TypeError376 ),377 FST_ERR_ROUTE_DUPLICATED_HANDLER: createError(378 'FST_ERR_ROUTE_DUPLICATED_HANDLER',379 'Duplicate handler for "%s:%s" route is not allowed!',380 500381 ),382 FST_ERR_ROUTE_HANDLER_NOT_FN: createError(383 'FST_ERR_ROUTE_HANDLER_NOT_FN',384 'Error Handler for %s:%s route, if defined, must be a function',385 500,386 TypeError387 ),388 FST_ERR_ROUTE_MISSING_HANDLER: createError(389 'FST_ERR_ROUTE_MISSING_HANDLER',390 'Missing handler function for "%s:%s" route.',391 500392 ),393 FST_ERR_ROUTE_METHOD_INVALID: createError(394 'FST_ERR_ROUTE_METHOD_INVALID',395 'Provided method is invalid!',396 500,397 TypeError398 ),399 FST_ERR_ROUTE_METHOD_NOT_SUPPORTED: createError(400 'FST_ERR_ROUTE_METHOD_NOT_SUPPORTED',401 '%s method is not supported.',402 500403 ),404 FST_ERR_ROUTE_BODY_VALIDATION_SCHEMA_NOT_SUPPORTED: createError(405 'FST_ERR_ROUTE_BODY_VALIDATION_SCHEMA_NOT_SUPPORTED',406 'Body validation schema for %s:%s route is not supported!',407 500408 ),409 FST_ERR_ROUTE_BODY_LIMIT_OPTION_NOT_INT: createError(410 'FST_ERR_ROUTE_BODY_LIMIT_OPTION_NOT_INT',411 "'bodyLimit' option must be an integer > 0. Got '%s'",412 500,413 TypeError414 ),415 FST_ERR_ROUTE_REWRITE_NOT_STR: createError(416 'FST_ERR_ROUTE_REWRITE_NOT_STR',417 'Rewrite url for "%s" needs to be of type "string" but received "%s"',418 500,419 TypeError420 ),421 422 /**423 * again listen when close server424 */425 FST_ERR_REOPENED_CLOSE_SERVER: createError(426 'FST_ERR_REOPENED_CLOSE_SERVER',427 'Fastify has already been closed and cannot be reopened'428 ),429 FST_ERR_REOPENED_SERVER: createError(430 'FST_ERR_REOPENED_SERVER',431 'Fastify is already listening'432 ),433 FST_ERR_INSTANCE_ALREADY_LISTENING: createError(434 'FST_ERR_INSTANCE_ALREADY_LISTENING',435 'Fastify instance is already listening. %s'436 ),437 438 /**439 * plugin440 */441 FST_ERR_PLUGIN_VERSION_MISMATCH: createError(442 'FST_ERR_PLUGIN_VERSION_MISMATCH',443 "fastify-plugin: %s - expected '%s' fastify version, '%s' is installed"444 ),445 FST_ERR_PLUGIN_NOT_PRESENT_IN_INSTANCE: createError(446 'FST_ERR_PLUGIN_NOT_PRESENT_IN_INSTANCE',447 "The decorator '%s'%s is not present in %s"448 ),449 FST_ERR_PLUGIN_INVALID_ASYNC_HANDLER: createError(450 'FST_ERR_PLUGIN_INVALID_ASYNC_HANDLER',451 'The %s plugin being registered mixes async and callback styles. Async plugin should not mix async and callback style.',452 500,453 TypeError454 ),455 456 /**457 * Avvio Errors458 */459 FST_ERR_PLUGIN_CALLBACK_NOT_FN: createError(460 'FST_ERR_PLUGIN_CALLBACK_NOT_FN',461 'fastify-plugin: %s',462 500,463 TypeError464 ),465 FST_ERR_PLUGIN_NOT_VALID: createError(466 'FST_ERR_PLUGIN_NOT_VALID',467 'fastify-plugin: %s'468 ),469 FST_ERR_ROOT_PLG_BOOTED: createError(470 'FST_ERR_ROOT_PLG_BOOTED',471 'fastify-plugin: %s'472 ),473 FST_ERR_PARENT_PLUGIN_BOOTED: createError(474 'FST_ERR_PARENT_PLUGIN_BOOTED',475 'fastify-plugin: %s'476 ),477 FST_ERR_PLUGIN_TIMEOUT: createError(478 'FST_ERR_PLUGIN_TIMEOUT',479 'fastify-plugin: %s'480 )481}482 483function appendStackTrace (oldErr, newErr) {484 newErr.cause = oldErr485 486 return newErr487}488 489module.exports = codes490module.exports.appendStackTrace = appendStackTrace491module.exports.AVVIO_ERRORS_MAP = {492 AVV_ERR_CALLBACK_NOT_FN: codes.FST_ERR_PLUGIN_CALLBACK_NOT_FN,493 AVV_ERR_PLUGIN_NOT_VALID: codes.FST_ERR_PLUGIN_NOT_VALID,494 AVV_ERR_ROOT_PLG_BOOTED: codes.FST_ERR_ROOT_PLG_BOOTED,495 AVV_ERR_PARENT_PLG_LOADED: codes.FST_ERR_PARENT_PLUGIN_BOOTED,496 AVV_ERR_READY_TIMEOUT: codes.FST_ERR_PLUGIN_TIMEOUT,497 AVV_ERR_PLUGIN_EXEC_TIMEOUT: codes.FST_ERR_PLUGIN_TIMEOUT498}499 