Spaces:
Runtime error
Runtime error
File size: 38,220 Bytes
23ac194 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 |
'use strict'
const { test } = require('node:test')
const errors = require('../../lib/errors')
const { readFileSync } = require('node:fs')
const { resolve } = require('node:path')
const expectedErrors = 84
test(`should expose ${expectedErrors} errors`, t => {
t.plan(1)
const exportedKeys = Object.keys(errors)
let counter = 0
for (const key of exportedKeys) {
if (errors[key].name === 'FastifyError') {
counter++
}
}
t.assert.strictEqual(counter, expectedErrors)
})
test('ensure name and codes of Errors are identical', t => {
t.plan(expectedErrors)
const exportedKeys = Object.keys(errors)
for (const key of exportedKeys) {
if (errors[key].name === 'FastifyError') {
t.assert.strictEqual(key, new errors[key]().code, key)
}
}
})
test('FST_ERR_NOT_FOUND', t => {
t.plan(5)
const error = new errors.FST_ERR_NOT_FOUND()
t.assert.strictEqual(error.name, 'FastifyError')
t.assert.strictEqual(error.code, 'FST_ERR_NOT_FOUND')
t.assert.strictEqual(error.message, 'Not Found')
t.assert.strictEqual(error.statusCode, 404)
t.assert.ok(error instanceof Error)
})
test('FST_ERR_OPTIONS_NOT_OBJ', t => {
t.plan(5)
const error = new errors.FST_ERR_OPTIONS_NOT_OBJ()
t.assert.strictEqual(error.name, 'FastifyError')
t.assert.strictEqual(error.code, 'FST_ERR_OPTIONS_NOT_OBJ')
t.assert.strictEqual(error.message, 'Options must be an object')
t.assert.strictEqual(error.statusCode, 500)
t.assert.ok(error instanceof TypeError)
})
test('FST_ERR_QSP_NOT_FN', t => {
t.plan(5)
const error = new errors.FST_ERR_QSP_NOT_FN()
t.assert.strictEqual(error.name, 'FastifyError')
t.assert.strictEqual(error.code, 'FST_ERR_QSP_NOT_FN')
t.assert.strictEqual(error.message, "querystringParser option should be a function, instead got '%s'")
t.assert.strictEqual(error.statusCode, 500)
t.assert.ok(error instanceof TypeError)
})
test('FST_ERR_SCHEMA_CONTROLLER_BUCKET_OPT_NOT_FN', t => {
t.plan(5)
const error = new errors.FST_ERR_SCHEMA_CONTROLLER_BUCKET_OPT_NOT_FN()
t.assert.strictEqual(error.name, 'FastifyError')
t.assert.strictEqual(error.code, 'FST_ERR_SCHEMA_CONTROLLER_BUCKET_OPT_NOT_FN')
t.assert.strictEqual(error.message, "schemaController.bucket option should be a function, instead got '%s'")
t.assert.strictEqual(error.statusCode, 500)
t.assert.ok(error instanceof TypeError)
})
test('FST_ERR_SCHEMA_ERROR_FORMATTER_NOT_FN', t => {
t.plan(5)
const error = new errors.FST_ERR_SCHEMA_ERROR_FORMATTER_NOT_FN()
t.assert.strictEqual(error.name, 'FastifyError')
t.assert.strictEqual(error.code, 'FST_ERR_SCHEMA_ERROR_FORMATTER_NOT_FN')
t.assert.strictEqual(error.message, "schemaErrorFormatter option should be a non async function. Instead got '%s'.")
t.assert.strictEqual(error.statusCode, 500)
t.assert.ok(error instanceof TypeError)
})
test('FST_ERR_AJV_CUSTOM_OPTIONS_OPT_NOT_OBJ', t => {
t.plan(5)
const error = new errors.FST_ERR_AJV_CUSTOM_OPTIONS_OPT_NOT_OBJ()
t.assert.strictEqual(error.name, 'FastifyError')
t.assert.strictEqual(error.code, 'FST_ERR_AJV_CUSTOM_OPTIONS_OPT_NOT_OBJ')
t.assert.strictEqual(error.message, "ajv.customOptions option should be an object, instead got '%s'")
t.assert.strictEqual(error.statusCode, 500)
t.assert.ok(error instanceof TypeError)
})
test('FST_ERR_AJV_CUSTOM_OPTIONS_OPT_NOT_ARR', t => {
t.plan(5)
const error = new errors.FST_ERR_AJV_CUSTOM_OPTIONS_OPT_NOT_ARR()
t.assert.strictEqual(error.name, 'FastifyError')
t.assert.strictEqual(error.code, 'FST_ERR_AJV_CUSTOM_OPTIONS_OPT_NOT_ARR')
t.assert.strictEqual(error.message, "ajv.plugins option should be an array, instead got '%s'")
t.assert.strictEqual(error.statusCode, 500)
t.assert.ok(error instanceof TypeError)
})
test('FST_ERR_CTP_ALREADY_PRESENT', t => {
t.plan(5)
const error = new errors.FST_ERR_CTP_ALREADY_PRESENT()
t.assert.strictEqual(error.name, 'FastifyError')
t.assert.strictEqual(error.code, 'FST_ERR_CTP_ALREADY_PRESENT')
t.assert.strictEqual(error.message, "Content type parser '%s' already present.")
t.assert.strictEqual(error.statusCode, 500)
t.assert.ok(error instanceof Error)
})
test('FST_ERR_CTP_INVALID_TYPE', t => {
t.plan(5)
const error = new errors.FST_ERR_CTP_INVALID_TYPE()
t.assert.strictEqual(error.name, 'FastifyError')
t.assert.strictEqual(error.code, 'FST_ERR_CTP_INVALID_TYPE')
t.assert.strictEqual(error.message, 'The content type should be a string or a RegExp')
t.assert.strictEqual(error.statusCode, 500)
t.assert.ok(error instanceof TypeError)
})
test('FST_ERR_CTP_EMPTY_TYPE', t => {
t.plan(5)
const error = new errors.FST_ERR_CTP_EMPTY_TYPE()
t.assert.strictEqual(error.name, 'FastifyError')
t.assert.strictEqual(error.code, 'FST_ERR_CTP_EMPTY_TYPE')
t.assert.strictEqual(error.message, 'The content type cannot be an empty string')
t.assert.strictEqual(error.statusCode, 500)
t.assert.ok(error instanceof TypeError)
})
test('FST_ERR_CTP_INVALID_HANDLER', t => {
t.plan(5)
const error = new errors.FST_ERR_CTP_INVALID_HANDLER()
t.assert.strictEqual(error.name, 'FastifyError')
t.assert.strictEqual(error.code, 'FST_ERR_CTP_INVALID_HANDLER')
t.assert.strictEqual(error.message, 'The content type handler should be a function')
t.assert.strictEqual(error.statusCode, 500)
t.assert.ok(error instanceof TypeError)
})
test('FST_ERR_CTP_INVALID_PARSE_TYPE', t => {
t.plan(5)
const error = new errors.FST_ERR_CTP_INVALID_PARSE_TYPE()
t.assert.strictEqual(error.name, 'FastifyError')
t.assert.strictEqual(error.code, 'FST_ERR_CTP_INVALID_PARSE_TYPE')
t.assert.strictEqual(error.message, "The body parser can only parse your data as 'string' or 'buffer', you asked '%s' which is not supported.")
t.assert.strictEqual(error.statusCode, 500)
t.assert.ok(error instanceof TypeError)
})
test('FST_ERR_CTP_BODY_TOO_LARGE', t => {
t.plan(5)
const error = new errors.FST_ERR_CTP_BODY_TOO_LARGE()
t.assert.strictEqual(error.name, 'FastifyError')
t.assert.strictEqual(error.code, 'FST_ERR_CTP_BODY_TOO_LARGE')
t.assert.strictEqual(error.message, 'Request body is too large')
t.assert.strictEqual(error.statusCode, 413)
t.assert.ok(error instanceof RangeError)
})
test('FST_ERR_CTP_INVALID_MEDIA_TYPE', t => {
t.plan(5)
const error = new errors.FST_ERR_CTP_INVALID_MEDIA_TYPE()
t.assert.strictEqual(error.name, 'FastifyError')
t.assert.strictEqual(error.code, 'FST_ERR_CTP_INVALID_MEDIA_TYPE')
t.assert.strictEqual(error.message, 'Unsupported Media Type: %s')
t.assert.strictEqual(error.statusCode, 415)
t.assert.ok(error instanceof Error)
})
test('FST_ERR_CTP_INVALID_CONTENT_LENGTH', t => {
t.plan(5)
const error = new errors.FST_ERR_CTP_INVALID_CONTENT_LENGTH()
t.assert.strictEqual(error.name, 'FastifyError')
t.assert.strictEqual(error.code, 'FST_ERR_CTP_INVALID_CONTENT_LENGTH')
t.assert.strictEqual(error.message, 'Request body size did not match Content-Length')
t.assert.strictEqual(error.statusCode, 400)
t.assert.ok(error instanceof RangeError)
})
test('FST_ERR_CTP_EMPTY_JSON_BODY', t => {
t.plan(5)
const error = new errors.FST_ERR_CTP_EMPTY_JSON_BODY()
t.assert.strictEqual(error.name, 'FastifyError')
t.assert.strictEqual(error.code, 'FST_ERR_CTP_EMPTY_JSON_BODY')
t.assert.strictEqual(error.message, "Body cannot be empty when content-type is set to 'application/json'")
t.assert.strictEqual(error.statusCode, 400)
t.assert.ok(error instanceof Error)
})
test('FST_ERR_CTP_INSTANCE_ALREADY_STARTED', t => {
t.plan(5)
const error = new errors.FST_ERR_CTP_INSTANCE_ALREADY_STARTED()
t.assert.strictEqual(error.name, 'FastifyError')
t.assert.strictEqual(error.code, 'FST_ERR_CTP_INSTANCE_ALREADY_STARTED')
t.assert.strictEqual(error.message, 'Cannot call "%s" when fastify instance is already started!')
t.assert.strictEqual(error.statusCode, 400)
t.assert.ok(error instanceof Error)
})
test('FST_ERR_DEC_ALREADY_PRESENT', t => {
t.plan(5)
const error = new errors.FST_ERR_DEC_ALREADY_PRESENT()
t.assert.strictEqual(error.name, 'FastifyError')
t.assert.strictEqual(error.code, 'FST_ERR_DEC_ALREADY_PRESENT')
t.assert.strictEqual(error.message, "The decorator '%s' has already been added!")
t.assert.strictEqual(error.statusCode, 500)
t.assert.ok(error instanceof Error)
})
test('FST_ERR_DEC_DEPENDENCY_INVALID_TYPE', t => {
t.plan(5)
const error = new errors.FST_ERR_DEC_DEPENDENCY_INVALID_TYPE()
t.assert.strictEqual(error.name, 'FastifyError')
t.assert.strictEqual(error.code, 'FST_ERR_DEC_DEPENDENCY_INVALID_TYPE')
t.assert.strictEqual(error.message, "The dependencies of decorator '%s' must be of type Array.")
t.assert.strictEqual(error.statusCode, 500)
t.assert.ok(error instanceof TypeError)
})
test('FST_ERR_DEC_MISSING_DEPENDENCY', t => {
t.plan(5)
const error = new errors.FST_ERR_DEC_MISSING_DEPENDENCY()
t.assert.strictEqual(error.name, 'FastifyError')
t.assert.strictEqual(error.code, 'FST_ERR_DEC_MISSING_DEPENDENCY')
t.assert.strictEqual(error.message, "The decorator is missing dependency '%s'.")
t.assert.strictEqual(error.statusCode, 500)
t.assert.ok(error instanceof Error)
})
test('FST_ERR_DEC_AFTER_START', t => {
t.plan(5)
const error = new errors.FST_ERR_DEC_AFTER_START()
t.assert.strictEqual(error.name, 'FastifyError')
t.assert.strictEqual(error.code, 'FST_ERR_DEC_AFTER_START')
t.assert.strictEqual(error.message, "The decorator '%s' has been added after start!")
t.assert.strictEqual(error.statusCode, 500)
t.assert.ok(error instanceof Error)
})
test('FST_ERR_DEC_REFERENCE_TYPE', t => {
t.plan(5)
const error = new errors.FST_ERR_DEC_REFERENCE_TYPE()
t.assert.strictEqual(error.name, 'FastifyError')
t.assert.strictEqual(error.code, 'FST_ERR_DEC_REFERENCE_TYPE')
t.assert.strictEqual(error.message, "The decorator '%s' of type '%s' is a reference type. Use the { getter, setter } interface instead.")
t.assert.strictEqual(error.statusCode, 500)
t.assert.ok(error instanceof Error)
})
test('FST_ERR_HOOK_INVALID_TYPE', t => {
t.plan(5)
const error = new errors.FST_ERR_HOOK_INVALID_TYPE()
t.assert.strictEqual(error.name, 'FastifyError')
t.assert.strictEqual(error.code, 'FST_ERR_HOOK_INVALID_TYPE')
t.assert.strictEqual(error.message, 'The hook name must be a string')
t.assert.strictEqual(error.statusCode, 500)
t.assert.ok(error instanceof TypeError)
})
test('FST_ERR_HOOK_INVALID_HANDLER', t => {
t.plan(5)
const error = new errors.FST_ERR_HOOK_INVALID_HANDLER()
t.assert.strictEqual(error.name, 'FastifyError')
t.assert.strictEqual(error.code, 'FST_ERR_HOOK_INVALID_HANDLER')
t.assert.strictEqual(error.message, '%s hook should be a function, instead got %s')
t.assert.strictEqual(error.statusCode, 500)
t.assert.ok(error instanceof TypeError)
})
test('FST_ERR_HOOK_INVALID_ASYNC_HANDLER', t => {
t.plan(5)
const error = new errors.FST_ERR_HOOK_INVALID_ASYNC_HANDLER()
t.assert.strictEqual(error.name, 'FastifyError')
t.assert.strictEqual(error.code, 'FST_ERR_HOOK_INVALID_ASYNC_HANDLER')
t.assert.strictEqual(error.message, "Async function has too many arguments. Async hooks should not use the 'done' argument.")
t.assert.strictEqual(error.statusCode, 500)
t.assert.ok(error instanceof TypeError)
})
test('FST_ERR_HOOK_NOT_SUPPORTED', t => {
t.plan(5)
const error = new errors.FST_ERR_HOOK_NOT_SUPPORTED()
t.assert.strictEqual(error.name, 'FastifyError')
t.assert.strictEqual(error.code, 'FST_ERR_HOOK_NOT_SUPPORTED')
t.assert.strictEqual(error.message, '%s hook not supported!')
t.assert.strictEqual(error.statusCode, 500)
t.assert.ok(error instanceof TypeError)
})
test('FST_ERR_MISSING_MIDDLEWARE', t => {
t.plan(5)
const error = new errors.FST_ERR_MISSING_MIDDLEWARE()
t.assert.strictEqual(error.name, 'FastifyError')
t.assert.strictEqual(error.code, 'FST_ERR_MISSING_MIDDLEWARE')
t.assert.strictEqual(error.message, 'You must register a plugin for handling middlewares, visit fastify.dev/docs/latest/Reference/Middleware/ for more info.')
t.assert.strictEqual(error.statusCode, 500)
t.assert.ok(error instanceof Error)
})
test('FST_ERR_HOOK_TIMEOUT', t => {
t.plan(5)
const error = new errors.FST_ERR_HOOK_TIMEOUT()
t.assert.strictEqual(error.name, 'FastifyError')
t.assert.strictEqual(error.code, 'FST_ERR_HOOK_TIMEOUT')
t.assert.strictEqual(error.message, "A callback for '%s' hook%s timed out. You may have forgotten to call 'done' function or to resolve a Promise")
t.assert.strictEqual(error.statusCode, 500)
t.assert.ok(error instanceof Error)
})
test('FST_ERR_LOG_INVALID_DESTINATION', t => {
t.plan(5)
const error = new errors.FST_ERR_LOG_INVALID_DESTINATION()
t.assert.strictEqual(error.name, 'FastifyError')
t.assert.strictEqual(error.code, 'FST_ERR_LOG_INVALID_DESTINATION')
t.assert.strictEqual(error.message, 'Cannot specify both logger.stream and logger.file options')
t.assert.strictEqual(error.statusCode, 500)
t.assert.ok(error instanceof Error)
})
test('FST_ERR_LOG_INVALID_LOGGER', t => {
t.plan(5)
const error = new errors.FST_ERR_LOG_INVALID_LOGGER()
t.assert.strictEqual(error.name, 'FastifyError')
t.assert.strictEqual(error.code, 'FST_ERR_LOG_INVALID_LOGGER')
t.assert.strictEqual(error.message, "Invalid logger object provided. The logger instance should have these functions(s): '%s'.")
t.assert.strictEqual(error.statusCode, 500)
t.assert.ok(error instanceof TypeError)
})
test('FST_ERR_LOG_INVALID_LOGGER_INSTANCE', t => {
t.plan(5)
const error = new errors.FST_ERR_LOG_INVALID_LOGGER_INSTANCE()
t.assert.strictEqual(error.name, 'FastifyError')
t.assert.strictEqual(error.code, 'FST_ERR_LOG_INVALID_LOGGER_INSTANCE')
t.assert.strictEqual(error.message, 'loggerInstance only accepts a logger instance.')
t.assert.strictEqual(error.statusCode, 500)
t.assert.ok(error instanceof TypeError)
})
test('FST_ERR_LOG_INVALID_LOGGER_CONFIG', t => {
t.plan(5)
const error = new errors.FST_ERR_LOG_INVALID_LOGGER_CONFIG()
t.assert.strictEqual(error.name, 'FastifyError')
t.assert.strictEqual(error.code, 'FST_ERR_LOG_INVALID_LOGGER_CONFIG')
t.assert.strictEqual(error.message, 'logger options only accepts a configuration object.')
t.assert.strictEqual(error.statusCode, 500)
t.assert.ok(error instanceof TypeError)
})
test('FST_ERR_LOG_LOGGER_AND_LOGGER_INSTANCE_PROVIDED', t => {
t.plan(5)
const error = new errors.FST_ERR_LOG_LOGGER_AND_LOGGER_INSTANCE_PROVIDED()
t.assert.strictEqual(error.name, 'FastifyError')
t.assert.strictEqual(error.code, 'FST_ERR_LOG_LOGGER_AND_LOGGER_INSTANCE_PROVIDED')
t.assert.strictEqual(error.message, 'You cannot provide both logger and loggerInstance. Please provide only one.')
t.assert.strictEqual(error.statusCode, 500)
t.assert.ok(error instanceof TypeError)
})
test('FST_ERR_REP_INVALID_PAYLOAD_TYPE', t => {
t.plan(5)
const error = new errors.FST_ERR_REP_INVALID_PAYLOAD_TYPE()
t.assert.strictEqual(error.name, 'FastifyError')
t.assert.strictEqual(error.code, 'FST_ERR_REP_INVALID_PAYLOAD_TYPE')
t.assert.strictEqual(error.message, "Attempted to send payload of invalid type '%s'. Expected a string or Buffer.")
t.assert.strictEqual(error.statusCode, 500)
t.assert.ok(error instanceof TypeError)
})
test('FST_ERR_REP_RESPONSE_BODY_CONSUMED', t => {
t.plan(5)
const error = new errors.FST_ERR_REP_RESPONSE_BODY_CONSUMED()
t.assert.strictEqual(error.name, 'FastifyError')
t.assert.strictEqual(error.code, 'FST_ERR_REP_RESPONSE_BODY_CONSUMED')
t.assert.strictEqual(error.message, 'Response.body is already consumed.')
t.assert.strictEqual(error.statusCode, 500)
t.assert.ok(error instanceof Error)
})
test('FST_ERR_REP_READABLE_STREAM_LOCKED', t => {
t.plan(5)
const error = new errors.FST_ERR_REP_READABLE_STREAM_LOCKED()
t.assert.strictEqual(error.name, 'FastifyError')
t.assert.strictEqual(error.code, 'FST_ERR_REP_READABLE_STREAM_LOCKED')
t.assert.strictEqual(error.message, 'ReadableStream was locked. You should call releaseLock() method on reader before sending.')
t.assert.strictEqual(error.statusCode, 500)
t.assert.ok(error instanceof Error)
})
test('FST_ERR_REP_ALREADY_SENT', t => {
t.plan(5)
const error = new errors.FST_ERR_REP_ALREADY_SENT('/hello', 'GET')
t.assert.strictEqual(error.name, 'FastifyError')
t.assert.strictEqual(error.code, 'FST_ERR_REP_ALREADY_SENT')
t.assert.strictEqual(error.message, 'Reply was already sent, did you forget to "return reply" in "/hello" (GET)?')
t.assert.strictEqual(error.statusCode, 500)
t.assert.ok(error instanceof Error)
})
test('FST_ERR_REP_SENT_VALUE', t => {
t.plan(5)
const error = new errors.FST_ERR_REP_SENT_VALUE()
t.assert.strictEqual(error.name, 'FastifyError')
t.assert.strictEqual(error.code, 'FST_ERR_REP_SENT_VALUE')
t.assert.strictEqual(error.message, 'The only possible value for reply.sent is true.')
t.assert.strictEqual(error.statusCode, 500)
t.assert.ok(error instanceof TypeError)
})
test('FST_ERR_SEND_INSIDE_ONERR', t => {
t.plan(5)
const error = new errors.FST_ERR_SEND_INSIDE_ONERR()
t.assert.strictEqual(error.name, 'FastifyError')
t.assert.strictEqual(error.code, 'FST_ERR_SEND_INSIDE_ONERR')
t.assert.strictEqual(error.message, 'You cannot use `send` inside the `onError` hook')
t.assert.strictEqual(error.statusCode, 500)
t.assert.ok(error instanceof Error)
})
test('FST_ERR_SEND_UNDEFINED_ERR', t => {
t.plan(5)
const error = new errors.FST_ERR_SEND_UNDEFINED_ERR()
t.assert.strictEqual(error.name, 'FastifyError')
t.assert.strictEqual(error.code, 'FST_ERR_SEND_UNDEFINED_ERR')
t.assert.strictEqual(error.message, 'Undefined error has occurred')
t.assert.strictEqual(error.statusCode, 500)
t.assert.ok(error instanceof Error)
})
test('FST_ERR_BAD_STATUS_CODE', t => {
t.plan(5)
const error = new errors.FST_ERR_BAD_STATUS_CODE()
t.assert.strictEqual(error.name, 'FastifyError')
t.assert.strictEqual(error.code, 'FST_ERR_BAD_STATUS_CODE')
t.assert.strictEqual(error.message, 'Called reply with an invalid status code: %s')
t.assert.strictEqual(error.statusCode, 500)
t.assert.ok(error instanceof Error)
})
test('FST_ERR_BAD_TRAILER_NAME', t => {
t.plan(5)
const error = new errors.FST_ERR_BAD_TRAILER_NAME()
t.assert.strictEqual(error.name, 'FastifyError')
t.assert.strictEqual(error.code, 'FST_ERR_BAD_TRAILER_NAME')
t.assert.strictEqual(error.message, 'Called reply.trailer with an invalid header name: %s')
t.assert.strictEqual(error.statusCode, 500)
t.assert.ok(error instanceof Error)
})
test('FST_ERR_BAD_TRAILER_VALUE', t => {
t.plan(5)
const error = new errors.FST_ERR_BAD_TRAILER_VALUE()
t.assert.strictEqual(error.name, 'FastifyError')
t.assert.strictEqual(error.code, 'FST_ERR_BAD_TRAILER_VALUE')
t.assert.strictEqual(error.message, "Called reply.trailer('%s', fn) with an invalid type: %s. Expected a function.")
t.assert.strictEqual(error.statusCode, 500)
t.assert.ok(error instanceof Error)
})
test('FST_ERR_FAILED_ERROR_SERIALIZATION', t => {
t.plan(5)
const error = new errors.FST_ERR_FAILED_ERROR_SERIALIZATION()
t.assert.strictEqual(error.name, 'FastifyError')
t.assert.strictEqual(error.code, 'FST_ERR_FAILED_ERROR_SERIALIZATION')
t.assert.strictEqual(error.message, 'Failed to serialize an error. Error: %s. Original error: %s')
t.assert.strictEqual(error.statusCode, 500)
t.assert.ok(error instanceof Error)
})
test('FST_ERR_MISSING_SERIALIZATION_FN', t => {
t.plan(5)
const error = new errors.FST_ERR_MISSING_SERIALIZATION_FN()
t.assert.strictEqual(error.name, 'FastifyError')
t.assert.strictEqual(error.code, 'FST_ERR_MISSING_SERIALIZATION_FN')
t.assert.strictEqual(error.message, 'Missing serialization function. Key "%s"')
t.assert.strictEqual(error.statusCode, 500)
t.assert.ok(error instanceof Error)
})
test('FST_ERR_MISSING_CONTENTTYPE_SERIALIZATION_FN', t => {
t.plan(5)
const error = new errors.FST_ERR_MISSING_CONTENTTYPE_SERIALIZATION_FN()
t.assert.strictEqual(error.name, 'FastifyError')
t.assert.strictEqual(error.code, 'FST_ERR_MISSING_CONTENTTYPE_SERIALIZATION_FN')
t.assert.strictEqual(error.message, 'Missing serialization function. Key "%s:%s"')
t.assert.strictEqual(error.statusCode, 500)
t.assert.ok(error instanceof Error)
})
test('FST_ERR_REQ_INVALID_VALIDATION_INVOCATION', t => {
t.plan(5)
const error = new errors.FST_ERR_REQ_INVALID_VALIDATION_INVOCATION()
t.assert.strictEqual(error.name, 'FastifyError')
t.assert.strictEqual(error.code, 'FST_ERR_REQ_INVALID_VALIDATION_INVOCATION')
t.assert.strictEqual(error.message, 'Invalid validation invocation. Missing validation function for HTTP part "%s" nor schema provided.')
t.assert.strictEqual(error.statusCode, 500)
t.assert.ok(error instanceof Error)
})
test('FST_ERR_SCH_MISSING_ID', t => {
t.plan(5)
const error = new errors.FST_ERR_SCH_MISSING_ID()
t.assert.strictEqual(error.name, 'FastifyError')
t.assert.strictEqual(error.code, 'FST_ERR_SCH_MISSING_ID')
t.assert.strictEqual(error.message, 'Missing schema $id property')
t.assert.strictEqual(error.statusCode, 500)
t.assert.ok(error instanceof Error)
})
test('FST_ERR_SCH_ALREADY_PRESENT', t => {
t.plan(5)
const error = new errors.FST_ERR_SCH_ALREADY_PRESENT()
t.assert.strictEqual(error.name, 'FastifyError')
t.assert.strictEqual(error.code, 'FST_ERR_SCH_ALREADY_PRESENT')
t.assert.strictEqual(error.message, "Schema with id '%s' already declared!")
t.assert.strictEqual(error.statusCode, 500)
t.assert.ok(error instanceof Error)
})
test('FST_ERR_SCH_CONTENT_MISSING_SCHEMA', t => {
t.plan(5)
const error = new errors.FST_ERR_SCH_CONTENT_MISSING_SCHEMA()
t.assert.strictEqual(error.name, 'FastifyError')
t.assert.strictEqual(error.code, 'FST_ERR_SCH_CONTENT_MISSING_SCHEMA')
t.assert.strictEqual(error.message, "Schema is missing for the content type '%s'")
t.assert.strictEqual(error.statusCode, 500)
t.assert.ok(error instanceof Error)
})
test('FST_ERR_SCH_DUPLICATE', t => {
t.plan(5)
const error = new errors.FST_ERR_SCH_DUPLICATE()
t.assert.strictEqual(error.name, 'FastifyError')
t.assert.strictEqual(error.code, 'FST_ERR_SCH_DUPLICATE')
t.assert.strictEqual(error.message, "Schema with '%s' already present!")
t.assert.strictEqual(error.statusCode, 500)
t.assert.ok(error instanceof Error)
})
test('FST_ERR_SCH_VALIDATION_BUILD', t => {
t.plan(5)
const error = new errors.FST_ERR_SCH_VALIDATION_BUILD()
t.assert.strictEqual(error.name, 'FastifyError')
t.assert.strictEqual(error.code, 'FST_ERR_SCH_VALIDATION_BUILD')
t.assert.strictEqual(error.message, 'Failed building the validation schema for %s: %s, due to error %s')
t.assert.strictEqual(error.statusCode, 500)
t.assert.ok(error instanceof Error)
})
test('FST_ERR_SCH_SERIALIZATION_BUILD', t => {
t.plan(5)
const error = new errors.FST_ERR_SCH_SERIALIZATION_BUILD()
t.assert.strictEqual(error.name, 'FastifyError')
t.assert.strictEqual(error.code, 'FST_ERR_SCH_SERIALIZATION_BUILD')
t.assert.strictEqual(error.message, 'Failed building the serialization schema for %s: %s, due to error %s')
t.assert.strictEqual(error.statusCode, 500)
t.assert.ok(error instanceof Error)
})
test('FST_ERR_SCH_RESPONSE_SCHEMA_NOT_NESTED_2XX', t => {
t.plan(5)
const error = new errors.FST_ERR_SCH_RESPONSE_SCHEMA_NOT_NESTED_2XX()
t.assert.strictEqual(error.name, 'FastifyError')
t.assert.strictEqual(error.code, 'FST_ERR_SCH_RESPONSE_SCHEMA_NOT_NESTED_2XX')
t.assert.strictEqual(error.message, 'response schemas should be nested under a valid status code, e.g { 2xx: { type: "object" } }')
t.assert.strictEqual(error.statusCode, 500)
t.assert.ok(error instanceof Error)
})
test('FST_ERR_HTTP2_INVALID_VERSION', t => {
t.plan(5)
const error = new errors.FST_ERR_HTTP2_INVALID_VERSION()
t.assert.strictEqual(error.name, 'FastifyError')
t.assert.strictEqual(error.code, 'FST_ERR_HTTP2_INVALID_VERSION')
t.assert.strictEqual(error.message, 'HTTP2 is available only from node >= 8.8.1')
t.assert.strictEqual(error.statusCode, 500)
t.assert.ok(error instanceof Error)
})
test('FST_ERR_INIT_OPTS_INVALID', t => {
t.plan(5)
const error = new errors.FST_ERR_INIT_OPTS_INVALID()
t.assert.strictEqual(error.name, 'FastifyError')
t.assert.strictEqual(error.code, 'FST_ERR_INIT_OPTS_INVALID')
t.assert.strictEqual(error.message, "Invalid initialization options: '%s'")
t.assert.strictEqual(error.statusCode, 500)
t.assert.ok(error instanceof Error)
})
test('FST_ERR_FORCE_CLOSE_CONNECTIONS_IDLE_NOT_AVAILABLE', t => {
t.plan(5)
const error = new errors.FST_ERR_FORCE_CLOSE_CONNECTIONS_IDLE_NOT_AVAILABLE()
t.assert.strictEqual(error.name, 'FastifyError')
t.assert.strictEqual(error.code, 'FST_ERR_FORCE_CLOSE_CONNECTIONS_IDLE_NOT_AVAILABLE')
t.assert.strictEqual(error.message, "Cannot set forceCloseConnections to 'idle' as your HTTP server does not support closeIdleConnections method")
t.assert.strictEqual(error.statusCode, 500)
t.assert.ok(error instanceof Error)
})
test('FST_ERR_DUPLICATED_ROUTE', t => {
t.plan(5)
const error = new errors.FST_ERR_DUPLICATED_ROUTE()
t.assert.strictEqual(error.name, 'FastifyError')
t.assert.strictEqual(error.code, 'FST_ERR_DUPLICATED_ROUTE')
t.assert.strictEqual(error.message, "Method '%s' already declared for route '%s'")
t.assert.strictEqual(error.statusCode, 500)
t.assert.ok(error instanceof Error)
})
test('FST_ERR_BAD_URL', t => {
t.plan(5)
const error = new errors.FST_ERR_BAD_URL()
t.assert.strictEqual(error.name, 'FastifyError')
t.assert.strictEqual(error.code, 'FST_ERR_BAD_URL')
t.assert.strictEqual(error.message, "'%s' is not a valid url component")
t.assert.strictEqual(error.statusCode, 400)
t.assert.ok(error instanceof Error)
})
test('FST_ERR_ASYNC_CONSTRAINT', t => {
t.plan(5)
const error = new errors.FST_ERR_ASYNC_CONSTRAINT()
t.assert.strictEqual(error.name, 'FastifyError')
t.assert.strictEqual(error.code, 'FST_ERR_ASYNC_CONSTRAINT')
t.assert.strictEqual(error.message, 'Unexpected error from async constraint')
t.assert.strictEqual(error.statusCode, 500)
t.assert.ok(error instanceof Error)
})
test('FST_ERR_INVALID_URL', t => {
t.plan(5)
const error = new errors.FST_ERR_INVALID_URL()
t.assert.strictEqual(error.name, 'FastifyError')
t.assert.strictEqual(error.code, 'FST_ERR_INVALID_URL')
t.assert.strictEqual(error.message, "URL must be a string. Received '%s'")
t.assert.strictEqual(error.statusCode, 400)
t.assert.ok(error instanceof TypeError)
})
test('FST_ERR_ROUTE_OPTIONS_NOT_OBJ', t => {
t.plan(5)
const error = new errors.FST_ERR_ROUTE_OPTIONS_NOT_OBJ()
t.assert.strictEqual(error.name, 'FastifyError')
t.assert.strictEqual(error.code, 'FST_ERR_ROUTE_OPTIONS_NOT_OBJ')
t.assert.strictEqual(error.message, 'Options for "%s:%s" route must be an object')
t.assert.strictEqual(error.statusCode, 500)
t.assert.ok(error instanceof TypeError)
})
test('FST_ERR_ROUTE_DUPLICATED_HANDLER', t => {
t.plan(5)
const error = new errors.FST_ERR_ROUTE_DUPLICATED_HANDLER()
t.assert.strictEqual(error.name, 'FastifyError')
t.assert.strictEqual(error.code, 'FST_ERR_ROUTE_DUPLICATED_HANDLER')
t.assert.strictEqual(error.message, 'Duplicate handler for "%s:%s" route is not allowed!')
t.assert.strictEqual(error.statusCode, 500)
t.assert.ok(error instanceof Error)
})
test('FST_ERR_ROUTE_HANDLER_NOT_FN', t => {
t.plan(5)
const error = new errors.FST_ERR_ROUTE_HANDLER_NOT_FN()
t.assert.strictEqual(error.name, 'FastifyError')
t.assert.strictEqual(error.code, 'FST_ERR_ROUTE_HANDLER_NOT_FN')
t.assert.strictEqual(error.message, 'Error Handler for %s:%s route, if defined, must be a function')
t.assert.strictEqual(error.statusCode, 500)
t.assert.ok(error instanceof TypeError)
})
test('FST_ERR_ROUTE_MISSING_HANDLER', t => {
t.plan(5)
const error = new errors.FST_ERR_ROUTE_MISSING_HANDLER()
t.assert.strictEqual(error.name, 'FastifyError')
t.assert.strictEqual(error.code, 'FST_ERR_ROUTE_MISSING_HANDLER')
t.assert.strictEqual(error.message, 'Missing handler function for "%s:%s" route.')
t.assert.strictEqual(error.statusCode, 500)
t.assert.ok(error instanceof Error)
})
test('FST_ERR_ROUTE_METHOD_INVALID', t => {
t.plan(5)
const error = new errors.FST_ERR_ROUTE_METHOD_INVALID()
t.assert.strictEqual(error.name, 'FastifyError')
t.assert.strictEqual(error.code, 'FST_ERR_ROUTE_METHOD_INVALID')
t.assert.strictEqual(error.message, 'Provided method is invalid!')
t.assert.strictEqual(error.statusCode, 500)
t.assert.ok(error instanceof TypeError)
})
test('FST_ERR_ROUTE_METHOD_NOT_SUPPORTED', t => {
t.plan(5)
const error = new errors.FST_ERR_ROUTE_METHOD_NOT_SUPPORTED()
t.assert.strictEqual(error.name, 'FastifyError')
t.assert.strictEqual(error.code, 'FST_ERR_ROUTE_METHOD_NOT_SUPPORTED')
t.assert.strictEqual(error.message, '%s method is not supported.')
t.assert.strictEqual(error.statusCode, 500)
t.assert.ok(error instanceof Error)
})
test('FST_ERR_ROUTE_BODY_VALIDATION_SCHEMA_NOT_SUPPORTED', t => {
t.plan(5)
const error = new errors.FST_ERR_ROUTE_BODY_VALIDATION_SCHEMA_NOT_SUPPORTED()
t.assert.strictEqual(error.name, 'FastifyError')
t.assert.strictEqual(error.code, 'FST_ERR_ROUTE_BODY_VALIDATION_SCHEMA_NOT_SUPPORTED')
t.assert.strictEqual(error.message, 'Body validation schema for %s:%s route is not supported!')
t.assert.strictEqual(error.statusCode, 500)
t.assert.ok(error instanceof Error)
})
test('FST_ERR_ROUTE_BODY_LIMIT_OPTION_NOT_INT', t => {
t.plan(5)
const error = new errors.FST_ERR_ROUTE_BODY_LIMIT_OPTION_NOT_INT()
t.assert.strictEqual(error.name, 'FastifyError')
t.assert.strictEqual(error.code, 'FST_ERR_ROUTE_BODY_LIMIT_OPTION_NOT_INT')
t.assert.strictEqual(error.message, "'bodyLimit' option must be an integer > 0. Got '%s'")
t.assert.strictEqual(error.statusCode, 500)
t.assert.ok(error instanceof TypeError)
})
test('FST_ERR_ROUTE_BODY_LIMIT_OPTION_NOT_INT', t => {
t.plan(5)
const error = new errors.FST_ERR_ROUTE_BODY_LIMIT_OPTION_NOT_INT()
t.assert.strictEqual(error.name, 'FastifyError')
t.assert.strictEqual(error.code, 'FST_ERR_ROUTE_BODY_LIMIT_OPTION_NOT_INT')
t.assert.strictEqual(error.message, "'bodyLimit' option must be an integer > 0. Got '%s'")
t.assert.strictEqual(error.statusCode, 500)
t.assert.ok(error instanceof TypeError)
})
test('FST_ERR_ROUTE_REWRITE_NOT_STR', t => {
t.plan(5)
const error = new errors.FST_ERR_ROUTE_REWRITE_NOT_STR()
t.assert.strictEqual(error.name, 'FastifyError')
t.assert.strictEqual(error.code, 'FST_ERR_ROUTE_REWRITE_NOT_STR')
t.assert.strictEqual(error.message, 'Rewrite url for "%s" needs to be of type "string" but received "%s"')
t.assert.strictEqual(error.statusCode, 500)
t.assert.ok(error instanceof TypeError)
})
test('FST_ERR_REOPENED_CLOSE_SERVER', t => {
t.plan(5)
const error = new errors.FST_ERR_REOPENED_CLOSE_SERVER()
t.assert.strictEqual(error.name, 'FastifyError')
t.assert.strictEqual(error.code, 'FST_ERR_REOPENED_CLOSE_SERVER')
t.assert.strictEqual(error.message, 'Fastify has already been closed and cannot be reopened')
t.assert.strictEqual(error.statusCode, 500)
t.assert.ok(error instanceof Error)
})
test('FST_ERR_REOPENED_SERVER', t => {
t.plan(5)
const error = new errors.FST_ERR_REOPENED_SERVER()
t.assert.strictEqual(error.name, 'FastifyError')
t.assert.strictEqual(error.code, 'FST_ERR_REOPENED_SERVER')
t.assert.strictEqual(error.message, 'Fastify is already listening')
t.assert.strictEqual(error.statusCode, 500)
t.assert.ok(error instanceof Error)
})
test('FST_ERR_INSTANCE_ALREADY_LISTENING', t => {
t.plan(5)
const error = new errors.FST_ERR_INSTANCE_ALREADY_LISTENING()
t.assert.strictEqual(error.name, 'FastifyError')
t.assert.strictEqual(error.code, 'FST_ERR_INSTANCE_ALREADY_LISTENING')
t.assert.strictEqual(error.message, 'Fastify instance is already listening. %s')
t.assert.strictEqual(error.statusCode, 500)
t.assert.ok(error instanceof Error)
})
test('FST_ERR_PLUGIN_VERSION_MISMATCH', t => {
t.plan(5)
const error = new errors.FST_ERR_PLUGIN_VERSION_MISMATCH()
t.assert.strictEqual(error.name, 'FastifyError')
t.assert.strictEqual(error.code, 'FST_ERR_PLUGIN_VERSION_MISMATCH')
t.assert.strictEqual(error.message, "fastify-plugin: %s - expected '%s' fastify version, '%s' is installed")
t.assert.strictEqual(error.statusCode, 500)
t.assert.ok(error instanceof Error)
})
test('FST_ERR_PLUGIN_NOT_PRESENT_IN_INSTANCE', t => {
t.plan(5)
const error = new errors.FST_ERR_PLUGIN_NOT_PRESENT_IN_INSTANCE()
t.assert.strictEqual(error.name, 'FastifyError')
t.assert.strictEqual(error.code, 'FST_ERR_PLUGIN_NOT_PRESENT_IN_INSTANCE')
t.assert.strictEqual(error.message, "The decorator '%s'%s is not present in %s")
t.assert.strictEqual(error.statusCode, 500)
t.assert.ok(error instanceof Error)
})
test('FST_ERR_PLUGIN_INVALID_ASYNC_HANDLER', t => {
t.plan(5)
const error = new errors.FST_ERR_PLUGIN_INVALID_ASYNC_HANDLER('easter-egg')
t.assert.strictEqual(error.name, 'FastifyError')
t.assert.strictEqual(error.code, 'FST_ERR_PLUGIN_INVALID_ASYNC_HANDLER')
t.assert.strictEqual(error.message, 'The easter-egg plugin being registered mixes async and callback styles. Async plugin should not mix async and callback style.')
t.assert.strictEqual(error.statusCode, 500)
t.assert.ok(error instanceof TypeError)
})
test('FST_ERR_PLUGIN_CALLBACK_NOT_FN', t => {
t.plan(5)
const error = new errors.FST_ERR_PLUGIN_CALLBACK_NOT_FN()
t.assert.strictEqual(error.name, 'FastifyError')
t.assert.strictEqual(error.code, 'FST_ERR_PLUGIN_CALLBACK_NOT_FN')
t.assert.strictEqual(error.message, 'fastify-plugin: %s')
t.assert.strictEqual(error.statusCode, 500)
t.assert.ok(error instanceof TypeError)
})
test('FST_ERR_PLUGIN_NOT_VALID', t => {
t.plan(5)
const error = new errors.FST_ERR_PLUGIN_NOT_VALID()
t.assert.strictEqual(error.name, 'FastifyError')
t.assert.strictEqual(error.code, 'FST_ERR_PLUGIN_NOT_VALID')
t.assert.strictEqual(error.message, 'fastify-plugin: %s')
t.assert.strictEqual(error.statusCode, 500)
t.assert.ok(error instanceof Error)
})
test('FST_ERR_ROOT_PLG_BOOTED', t => {
t.plan(5)
const error = new errors.FST_ERR_ROOT_PLG_BOOTED()
t.assert.strictEqual(error.name, 'FastifyError')
t.assert.strictEqual(error.code, 'FST_ERR_ROOT_PLG_BOOTED')
t.assert.strictEqual(error.message, 'fastify-plugin: %s')
t.assert.strictEqual(error.statusCode, 500)
t.assert.ok(error instanceof Error)
})
test('FST_ERR_PARENT_PLUGIN_BOOTED', t => {
t.plan(5)
const error = new errors.FST_ERR_PARENT_PLUGIN_BOOTED()
t.assert.strictEqual(error.name, 'FastifyError')
t.assert.strictEqual(error.code, 'FST_ERR_PARENT_PLUGIN_BOOTED')
t.assert.strictEqual(error.message, 'fastify-plugin: %s')
t.assert.strictEqual(error.statusCode, 500)
t.assert.ok(error instanceof Error)
})
test('FST_ERR_PLUGIN_TIMEOUT', t => {
t.plan(5)
const error = new errors.FST_ERR_PLUGIN_TIMEOUT()
t.assert.strictEqual(error.name, 'FastifyError')
t.assert.strictEqual(error.code, 'FST_ERR_PLUGIN_TIMEOUT')
t.assert.strictEqual(error.message, 'fastify-plugin: %s')
t.assert.strictEqual(error.statusCode, 500)
t.assert.ok(error instanceof Error)
})
test('FST_ERR_VALIDATION', t => {
t.plan(5)
const error = new errors.FST_ERR_VALIDATION()
t.assert.strictEqual(error.name, 'FastifyError')
t.assert.strictEqual(error.code, 'FST_ERR_VALIDATION')
t.assert.strictEqual(error.message, '%s')
t.assert.strictEqual(error.statusCode, 400)
t.assert.ok(error instanceof Error)
})
test('FST_ERR_LISTEN_OPTIONS_INVALID', t => {
t.plan(5)
const error = new errors.FST_ERR_LISTEN_OPTIONS_INVALID()
t.assert.strictEqual(error.name, 'FastifyError')
t.assert.strictEqual(error.code, 'FST_ERR_LISTEN_OPTIONS_INVALID')
t.assert.strictEqual(error.message, "Invalid listen options: '%s'")
t.assert.strictEqual(error.statusCode, 500)
t.assert.ok(error instanceof TypeError)
})
test('FST_ERR_ERROR_HANDLER_NOT_FN', t => {
t.plan(5)
const error = new errors.FST_ERR_ERROR_HANDLER_NOT_FN()
t.assert.strictEqual(error.name, 'FastifyError')
t.assert.strictEqual(error.code, 'FST_ERR_ERROR_HANDLER_NOT_FN')
t.assert.strictEqual(error.message, 'Error Handler must be a function')
t.assert.strictEqual(error.statusCode, 500)
t.assert.ok(error instanceof TypeError)
})
test('Ensure that all errors are in Errors.md TOC', t => {
t.plan(expectedErrors)
const errorsMd = readFileSync(resolve(__dirname, '../../docs/Reference/Errors.md'), 'utf8')
const exportedKeys = Object.keys(errors)
for (const key of exportedKeys) {
if (errors[key].name === 'FastifyError') {
t.assert.ok(errorsMd.includes(` - [${key.toUpperCase()}](#${key.toLowerCase()})`), key)
}
}
})
test('Ensure that non-existing errors are not in Errors.md TOC', t => {
t.plan(expectedErrors)
const errorsMd = readFileSync(resolve(__dirname, '../../docs/Reference/Errors.md'), 'utf8')
const matchRE = / {4}- \[([A-Z0-9_]+)\]\(#[a-z0-9_]+\)/g
const matches = errorsMd.matchAll(matchRE)
const exportedKeys = Object.keys(errors)
for (const match of matches) {
t.assert.ok(exportedKeys.indexOf(match[1]) !== -1, match[1])
}
})
test('Ensure that all errors are in Errors.md documented', t => {
t.plan(expectedErrors)
const errorsMd = readFileSync(resolve(__dirname, '../../docs/Reference/Errors.md'), 'utf8')
const exportedKeys = Object.keys(errors)
for (const key of exportedKeys) {
if (errors[key].name === 'FastifyError') {
t.assert.ok(errorsMd.includes(`<a id="${key.toLowerCase()}">${key.toUpperCase()}</a>`), key)
}
}
})
test('Ensure that non-existing errors are not in Errors.md documented', t => {
t.plan(expectedErrors)
const errorsMd = readFileSync(resolve(__dirname, '../../docs/Reference/Errors.md'), 'utf8')
const matchRE = /<a id="[0-9a-zA-Z_]+">([0-9a-zA-Z_]+)<\/a>/g
const matches = errorsMd.matchAll(matchRE)
const exportedKeys = Object.keys(errors)
for (const match of matches) {
t.assert.ok(exportedKeys.indexOf(match[1]) !== -1, match[1])
}
})
|