@fastify/error 4.2.0 → 4.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.github/dependabot.yml +42 -2
- package/.github/workflows/ci.yml +6 -1
- package/.github/workflows/lock-threads.yml +19 -0
- package/.github/workflows/release.yml +24 -0
- package/LICENSE +1 -1
- package/package.json +5 -10
- package/test/instanceof.test.js +2 -2
- package/types/index.tst.ts +153 -0
- package/types/index.test-d.ts +0 -92
package/.github/dependabot.yml
CHANGED
|
@@ -2,12 +2,52 @@ version: 2
|
|
|
2
2
|
updates:
|
|
3
3
|
- package-ecosystem: "github-actions"
|
|
4
4
|
directory: "/"
|
|
5
|
+
commit-message:
|
|
6
|
+
# Prefix all commit messages with "chore: "
|
|
7
|
+
prefix: "chore"
|
|
5
8
|
schedule:
|
|
6
|
-
interval: "
|
|
9
|
+
interval: "weekly"
|
|
10
|
+
cooldown:
|
|
11
|
+
default-days: 7
|
|
12
|
+
allow:
|
|
13
|
+
- dependency-name: "*"
|
|
14
|
+
update-types:
|
|
15
|
+
- "version-update:semver-major"
|
|
7
16
|
open-pull-requests-limit: 10
|
|
8
17
|
|
|
9
18
|
- package-ecosystem: "npm"
|
|
10
19
|
directory: "/"
|
|
20
|
+
commit-message:
|
|
21
|
+
# Prefix all commit messages with "chore: "
|
|
22
|
+
prefix: "chore"
|
|
11
23
|
schedule:
|
|
12
|
-
interval: "
|
|
24
|
+
interval: "weekly"
|
|
25
|
+
cooldown:
|
|
26
|
+
default-days: 7
|
|
27
|
+
versioning-strategy: "increase-if-necessary"
|
|
28
|
+
allow:
|
|
29
|
+
- dependency-name: "*"
|
|
30
|
+
update-types:
|
|
31
|
+
- "version-update:semver-major"
|
|
32
|
+
ignore:
|
|
33
|
+
# TODO: remove ignore until neostandard support ESLint 10
|
|
34
|
+
- dependency-name: "eslint"
|
|
35
|
+
- dependency-name: "neostandard"
|
|
36
|
+
- dependency-name: "@stylistic/*"
|
|
13
37
|
open-pull-requests-limit: 10
|
|
38
|
+
groups:
|
|
39
|
+
# Production dependencies with breaking changes
|
|
40
|
+
dependencies:
|
|
41
|
+
dependency-type: "production"
|
|
42
|
+
# ESLint related dependencies
|
|
43
|
+
dev-dependencies-eslint:
|
|
44
|
+
patterns:
|
|
45
|
+
- "eslint"
|
|
46
|
+
- "neostandard"
|
|
47
|
+
- "@stylistic/*"
|
|
48
|
+
# TypeScript related dependencies
|
|
49
|
+
dev-dependencies-typescript:
|
|
50
|
+
patterns:
|
|
51
|
+
- "@types/*"
|
|
52
|
+
- "tstyche"
|
|
53
|
+
- "typescript"
|
package/.github/workflows/ci.yml
CHANGED
|
@@ -14,6 +14,11 @@ on:
|
|
|
14
14
|
- 'docs/**'
|
|
15
15
|
- '*.md'
|
|
16
16
|
|
|
17
|
+
# This allows a subsequently queued workflow run to interrupt previous runs
|
|
18
|
+
concurrency:
|
|
19
|
+
group: "${{ github.workflow }}-${{ github.event.pull_request.head.label || github.head_ref || github.ref }}"
|
|
20
|
+
cancel-in-progress: true
|
|
21
|
+
|
|
17
22
|
permissions:
|
|
18
23
|
contents: read
|
|
19
24
|
|
|
@@ -22,7 +27,7 @@ jobs:
|
|
|
22
27
|
permissions:
|
|
23
28
|
contents: write
|
|
24
29
|
pull-requests: write
|
|
25
|
-
uses: fastify/workflows/.github/workflows/plugins-ci.yml@
|
|
30
|
+
uses: fastify/workflows/.github/workflows/plugins-ci.yml@ef591e2186785d5ab36b9fe6a79c7ce2f1d94e57 # v7.0.0
|
|
26
31
|
with:
|
|
27
32
|
license-check: true
|
|
28
33
|
lint: true
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
name: Lock Threads
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
schedule:
|
|
5
|
+
- cron: '0 0 1 * *'
|
|
6
|
+
workflow_dispatch:
|
|
7
|
+
|
|
8
|
+
concurrency:
|
|
9
|
+
group: lock
|
|
10
|
+
|
|
11
|
+
permissions:
|
|
12
|
+
contents: read
|
|
13
|
+
|
|
14
|
+
jobs:
|
|
15
|
+
lock-threads:
|
|
16
|
+
permissions:
|
|
17
|
+
issues: write
|
|
18
|
+
pull-requests: write
|
|
19
|
+
uses: fastify/workflows/.github/workflows/lock-threads.yml@ef591e2186785d5ab36b9fe6a79c7ce2f1d94e57 # v7.0.0
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
name: Release the package
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
workflow_dispatch:
|
|
5
|
+
inputs:
|
|
6
|
+
semver:
|
|
7
|
+
description: 'Release bump type'
|
|
8
|
+
required: true
|
|
9
|
+
type: choice
|
|
10
|
+
options:
|
|
11
|
+
- patch
|
|
12
|
+
- minor
|
|
13
|
+
- major
|
|
14
|
+
|
|
15
|
+
permissions: {}
|
|
16
|
+
|
|
17
|
+
jobs:
|
|
18
|
+
release:
|
|
19
|
+
permissions:
|
|
20
|
+
id-token: write # required for npm provenance via OIDC
|
|
21
|
+
contents: write # required to push the release commit and the tag
|
|
22
|
+
uses: fastify/workflows/.github/workflows/reusable-release.yml@b1a11bce713bc857e52b2231fec3c89071ad3135
|
|
23
|
+
with:
|
|
24
|
+
semver: ${{ inputs.semver }}
|
package/LICENSE
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
MIT License
|
|
2
2
|
|
|
3
|
-
Copyright (c) 2020 Fastify
|
|
3
|
+
Copyright (c) 2020-present The Fastify team <https://github.com/fastify/fastify#team>
|
|
4
4
|
|
|
5
5
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
6
|
of this software and associated documentation files (the "Software"), to deal
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fastify/error",
|
|
3
|
-
"version": "4.2.
|
|
3
|
+
"version": "4.2.1",
|
|
4
4
|
"description": "A small utility, used by Fastify itself, for generating consistent error objects across your codebase and plugins.",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"type": "commonjs",
|
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
"lint:fix": "eslint --fix",
|
|
11
11
|
"test": "npm run test:unit && npm run test:typescript",
|
|
12
12
|
"test:unit": "c8 --100 node --test",
|
|
13
|
-
"test:typescript": "
|
|
13
|
+
"test:typescript": "tstyche"
|
|
14
14
|
},
|
|
15
15
|
"repository": {
|
|
16
16
|
"type": "git",
|
|
@@ -59,15 +59,10 @@
|
|
|
59
59
|
],
|
|
60
60
|
"devDependencies": {
|
|
61
61
|
"benchmark": "^2.1.4",
|
|
62
|
-
"c8": "^
|
|
62
|
+
"c8": "^12.0.0",
|
|
63
63
|
"eslint": "^9.17.0",
|
|
64
|
-
"neostandard": "^0.
|
|
65
|
-
"
|
|
66
|
-
},
|
|
67
|
-
"tsd": {
|
|
68
|
-
"compilerOptions": {
|
|
69
|
-
"esModuleInterop": true
|
|
70
|
-
}
|
|
64
|
+
"neostandard": "^0.13.0",
|
|
65
|
+
"tstyche": "^7.1.0"
|
|
71
66
|
},
|
|
72
67
|
"publishConfig": {
|
|
73
68
|
"access": "public"
|
package/test/instanceof.test.js
CHANGED
|
@@ -147,7 +147,7 @@ test('ensure that instanceof works accross different installations of the fastif
|
|
|
147
147
|
console.error('expectedPathOfFastifyError', expectedPathOfFastifyError)
|
|
148
148
|
throw new Error('fastify-error should be required from the node_modules directory of the test-project')
|
|
149
149
|
}
|
|
150
|
-
|
|
150
|
+
|
|
151
151
|
const Boom = createError('Boom', 'Boom', 500)
|
|
152
152
|
const ChildBoom = createError('ChildBoom', 'Boom', 500, Boom)
|
|
153
153
|
const NotChildBoom = createError('NotChildBoom', 'NotChildBoom', 500, Boom)
|
|
@@ -191,7 +191,7 @@ test('ensure that instanceof works accross different installations of the fastif
|
|
|
191
191
|
console.error('expectedPathOfFastifyError', expectedPathOfFastifyError)
|
|
192
192
|
throw new Error('fastify-error should be required from the node_modules directory of dep')
|
|
193
193
|
}
|
|
194
|
-
|
|
194
|
+
|
|
195
195
|
const Boom = createError('Boom', 'Boom', 500)
|
|
196
196
|
const ChildBoom = createError('ChildBoom', 'Boom', 500, Boom)
|
|
197
197
|
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
import { expect } from 'tstyche'
|
|
2
|
+
import createError, { FastifyError, FastifyErrorConstructor } from '..'
|
|
3
|
+
|
|
4
|
+
const CustomError = createError('ERROR_CODE', 'message')
|
|
5
|
+
expect(CustomError).type.toBe<
|
|
6
|
+
FastifyErrorConstructor<{ code: 'ERROR_CODE' }>
|
|
7
|
+
>()
|
|
8
|
+
const err = new CustomError()
|
|
9
|
+
expect(err).type.toBe<FastifyError & { code: 'ERROR_CODE' }>()
|
|
10
|
+
expect(err.code).type.toBe<'ERROR_CODE'>()
|
|
11
|
+
expect(err.message).type.toBe<string>()
|
|
12
|
+
expect(err.statusCode).type.toBe<number | undefined>()
|
|
13
|
+
|
|
14
|
+
const CustomErrorNoStackTrace = createError(
|
|
15
|
+
'ERROR_CODE',
|
|
16
|
+
'message',
|
|
17
|
+
undefined,
|
|
18
|
+
undefined,
|
|
19
|
+
false
|
|
20
|
+
)
|
|
21
|
+
expect(CustomErrorNoStackTrace).type.toBe<
|
|
22
|
+
FastifyErrorConstructor<{ code: 'ERROR_CODE' }>
|
|
23
|
+
>()
|
|
24
|
+
const errNoStackTrace = new CustomErrorNoStackTrace()
|
|
25
|
+
expect(errNoStackTrace).type.toBe<FastifyError & { code: 'ERROR_CODE' }>()
|
|
26
|
+
expect(errNoStackTrace.code).type.toBe<'ERROR_CODE'>()
|
|
27
|
+
expect(errNoStackTrace.message).type.toBe<string>()
|
|
28
|
+
expect(errNoStackTrace.statusCode).type.toBe<number | undefined>()
|
|
29
|
+
|
|
30
|
+
const CustomTypedError = createError('OTHER_CODE', 'message', 400)
|
|
31
|
+
expect(CustomTypedError).type.toBe<
|
|
32
|
+
FastifyErrorConstructor<{ code: 'OTHER_CODE'; statusCode: 400 }>
|
|
33
|
+
>()
|
|
34
|
+
const typed = new CustomTypedError()
|
|
35
|
+
expect(typed).type.toBe<
|
|
36
|
+
FastifyError & { code: 'OTHER_CODE'; statusCode: 400 }
|
|
37
|
+
>()
|
|
38
|
+
expect(typed.code).type.toBe<'OTHER_CODE'>()
|
|
39
|
+
expect(typed.message).type.toBe<string>()
|
|
40
|
+
expect(typed.statusCode).type.toBe<400>()
|
|
41
|
+
|
|
42
|
+
/* eslint-disable no-new */
|
|
43
|
+
const CustomTypedArgError = createError<[string]>(
|
|
44
|
+
'OTHER_CODE',
|
|
45
|
+
'expect %s message',
|
|
46
|
+
400
|
|
47
|
+
)
|
|
48
|
+
CustomTypedArgError('a')
|
|
49
|
+
expect(CustomTypedArgError).type.not.toBeCallableWith('a', 'b')
|
|
50
|
+
expect(CustomTypedArgError).type.not.toBeConstructableWith('a', 'b')
|
|
51
|
+
expect(CustomTypedArgError).type.not.toBeCallableWith(1)
|
|
52
|
+
expect(CustomTypedArgError).type.not.toBeConstructableWith(1)
|
|
53
|
+
|
|
54
|
+
const CustomTypedArgError2 = createError<string, number, [string]>(
|
|
55
|
+
'OTHER_CODE',
|
|
56
|
+
'expect %s message',
|
|
57
|
+
400
|
|
58
|
+
)
|
|
59
|
+
CustomTypedArgError2('a')
|
|
60
|
+
expect(CustomTypedArgError2).type.not.toBeCallableWith('a', 'b')
|
|
61
|
+
expect(CustomTypedArgError2).type.not.toBeConstructableWith('a', 'b')
|
|
62
|
+
expect(CustomTypedArgError2).type.not.toBeCallableWith(1)
|
|
63
|
+
expect(CustomTypedArgError2).type.not.toBeConstructableWith(1)
|
|
64
|
+
|
|
65
|
+
const CustomTypedArgError3 = createError<string, number, [string, string]>(
|
|
66
|
+
'OTHER_CODE',
|
|
67
|
+
'expect %s message but got %s',
|
|
68
|
+
400
|
|
69
|
+
)
|
|
70
|
+
expect(CustomTypedArgError3).type.not.toBeCallableWith('a')
|
|
71
|
+
CustomTypedArgError3('a', 'b')
|
|
72
|
+
new CustomTypedArgError3('a', 'b')
|
|
73
|
+
expect(CustomTypedArgError3).type.not.toBeCallableWith(1)
|
|
74
|
+
expect(CustomTypedArgError3).type.not.toBeConstructableWith(1)
|
|
75
|
+
expect(CustomTypedArgError3).type.not.toBeConstructableWith(1, 2)
|
|
76
|
+
expect(CustomTypedArgError3).type.not.toBeConstructableWith('1', 2)
|
|
77
|
+
expect(CustomTypedArgError3).type.not.toBeConstructableWith(1, '2')
|
|
78
|
+
|
|
79
|
+
const CustomTypedArgError4 = createError<string, number, [string, string]>(
|
|
80
|
+
'OTHER_CODE',
|
|
81
|
+
'expect %s message but got %s',
|
|
82
|
+
400
|
|
83
|
+
)
|
|
84
|
+
expect(CustomTypedArgError4).type.not.toBeCallableWith('a')
|
|
85
|
+
CustomTypedArgError4('a', 'b')
|
|
86
|
+
new CustomTypedArgError4('a', 'b')
|
|
87
|
+
expect(CustomTypedArgError4).type.not.toBeCallableWith(1)
|
|
88
|
+
expect(CustomTypedArgError4).type.not.toBeConstructableWith(1)
|
|
89
|
+
expect(CustomTypedArgError4).type.not.toBeConstructableWith(1, 2)
|
|
90
|
+
expect(CustomTypedArgError4).type.not.toBeConstructableWith('1', 2)
|
|
91
|
+
expect(CustomTypedArgError4).type.not.toBeConstructableWith(1, '2')
|
|
92
|
+
|
|
93
|
+
const CustomTypedArgError5 = createError<[string, string, string, string]>(
|
|
94
|
+
'OTHER_CODE',
|
|
95
|
+
'expect %s message but got %s. Please contact %s by emailing to %s',
|
|
96
|
+
400
|
|
97
|
+
)
|
|
98
|
+
expect(CustomTypedArgError5).type.not.toBeCallableWith('a')
|
|
99
|
+
expect(CustomTypedArgError5).type.not.toBeConstructableWith('a', 'b')
|
|
100
|
+
expect(CustomTypedArgError5).type.not.toBeConstructableWith('a', 'b', 'c')
|
|
101
|
+
CustomTypedArgError5('a', 'b', 'c', 'd')
|
|
102
|
+
expect(CustomTypedArgError5).type.not.toBeConstructableWith(
|
|
103
|
+
'a',
|
|
104
|
+
'b',
|
|
105
|
+
'c',
|
|
106
|
+
'd',
|
|
107
|
+
'e'
|
|
108
|
+
)
|
|
109
|
+
|
|
110
|
+
const CustomTypedArgError6 = createError<
|
|
111
|
+
string,
|
|
112
|
+
number,
|
|
113
|
+
[string, string, string, string]
|
|
114
|
+
>(
|
|
115
|
+
'OTHER_CODE',
|
|
116
|
+
'expect %s message but got %s. Please contact %s by emailing to %s',
|
|
117
|
+
400
|
|
118
|
+
)
|
|
119
|
+
expect(CustomTypedArgError6).type.not.toBeCallableWith('a')
|
|
120
|
+
expect(CustomTypedArgError6).type.not.toBeConstructableWith('a', 'b')
|
|
121
|
+
expect(CustomTypedArgError6).type.not.toBeConstructableWith('a', 'b', 'c')
|
|
122
|
+
CustomTypedArgError6('a', 'b', 'c', 'd')
|
|
123
|
+
expect(CustomTypedArgError6).type.not.toBeConstructableWith(
|
|
124
|
+
'a',
|
|
125
|
+
'b',
|
|
126
|
+
'c',
|
|
127
|
+
'd',
|
|
128
|
+
'e'
|
|
129
|
+
)
|
|
130
|
+
|
|
131
|
+
const CustomErrorWithErrorConstructor = createError(
|
|
132
|
+
'ERROR_CODE',
|
|
133
|
+
'message',
|
|
134
|
+
500,
|
|
135
|
+
TypeError
|
|
136
|
+
)
|
|
137
|
+
expect(CustomErrorWithErrorConstructor).type.toBe<
|
|
138
|
+
FastifyErrorConstructor<{ code: 'ERROR_CODE'; statusCode: 500 }>
|
|
139
|
+
>()
|
|
140
|
+
CustomErrorWithErrorConstructor({ cause: new Error('Error') })
|
|
141
|
+
const customErrorWithErrorConstructor = CustomErrorWithErrorConstructor()
|
|
142
|
+
if (customErrorWithErrorConstructor instanceof FastifyError) {
|
|
143
|
+
expect(customErrorWithErrorConstructor.code).type.toBe<'ERROR_CODE'>()
|
|
144
|
+
expect(customErrorWithErrorConstructor.message).type.toBe<string>()
|
|
145
|
+
expect(customErrorWithErrorConstructor.statusCode).type.toBe<500>()
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
const error = new FastifyError('ERROR_CODE', 'message', 500)
|
|
149
|
+
if (error instanceof FastifyError) {
|
|
150
|
+
expect(error.code).type.toBe<string>()
|
|
151
|
+
expect(error.message).type.toBe<string>()
|
|
152
|
+
expect(error.statusCode).type.toBe<number | undefined>()
|
|
153
|
+
}
|
package/types/index.test-d.ts
DELETED
|
@@ -1,92 +0,0 @@
|
|
|
1
|
-
import createError, { FastifyError, FastifyErrorConstructor } from '..'
|
|
2
|
-
import { expectType, expectError } from 'tsd'
|
|
3
|
-
|
|
4
|
-
const CustomError = createError('ERROR_CODE', 'message')
|
|
5
|
-
expectType<FastifyErrorConstructor<{ code: 'ERROR_CODE' }>>(CustomError)
|
|
6
|
-
const err = new CustomError()
|
|
7
|
-
expectType<FastifyError & { code: 'ERROR_CODE' }>(err)
|
|
8
|
-
expectType<'ERROR_CODE'>(err.code)
|
|
9
|
-
expectType<string>(err.message)
|
|
10
|
-
expectType<number | undefined>(err.statusCode)
|
|
11
|
-
|
|
12
|
-
const CustomErrorNoStackTrace = createError('ERROR_CODE', 'message', undefined, undefined, false)
|
|
13
|
-
expectType<FastifyErrorConstructor<{ code: 'ERROR_CODE' }>>(CustomErrorNoStackTrace)
|
|
14
|
-
const errNoStackTrace = new CustomErrorNoStackTrace()
|
|
15
|
-
expectType<FastifyError & { code: 'ERROR_CODE' }>(errNoStackTrace)
|
|
16
|
-
expectType<'ERROR_CODE'>(errNoStackTrace.code)
|
|
17
|
-
expectType<string>(errNoStackTrace.message)
|
|
18
|
-
expectType<number | undefined>(errNoStackTrace.statusCode)
|
|
19
|
-
|
|
20
|
-
const CustomTypedError = createError('OTHER_CODE', 'message', 400)
|
|
21
|
-
expectType<FastifyErrorConstructor<{ code: 'OTHER_CODE', statusCode: 400 }>>(CustomTypedError)
|
|
22
|
-
const typed = new CustomTypedError()
|
|
23
|
-
expectType<FastifyError & { code: 'OTHER_CODE', statusCode: 400 }>(typed)
|
|
24
|
-
expectType<'OTHER_CODE'>(typed.code)
|
|
25
|
-
expectType<string>(typed.message)
|
|
26
|
-
expectType<400>(typed.statusCode)
|
|
27
|
-
|
|
28
|
-
/* eslint-disable no-new */
|
|
29
|
-
const CustomTypedArgError = createError<[string]>('OTHER_CODE', 'expect %s message', 400)
|
|
30
|
-
CustomTypedArgError('a')
|
|
31
|
-
expectError(CustomTypedArgError('a', 'b'))
|
|
32
|
-
expectError(new CustomTypedArgError('a', 'b'))
|
|
33
|
-
expectError(CustomTypedArgError(1))
|
|
34
|
-
expectError(new CustomTypedArgError(1))
|
|
35
|
-
|
|
36
|
-
const CustomTypedArgError2 = createError<string, number, [string]>('OTHER_CODE', 'expect %s message', 400)
|
|
37
|
-
CustomTypedArgError2('a')
|
|
38
|
-
expectError(CustomTypedArgError2('a', 'b'))
|
|
39
|
-
expectError(new CustomTypedArgError2('a', 'b'))
|
|
40
|
-
expectError(CustomTypedArgError2(1))
|
|
41
|
-
expectError(new CustomTypedArgError2(1))
|
|
42
|
-
|
|
43
|
-
const CustomTypedArgError3 = createError<string, number, [string, string]>('OTHER_CODE', 'expect %s message but got %s', 400)
|
|
44
|
-
expectError(CustomTypedArgError3('a'))
|
|
45
|
-
CustomTypedArgError3('a', 'b')
|
|
46
|
-
new CustomTypedArgError3('a', 'b')
|
|
47
|
-
expectError(CustomTypedArgError3(1))
|
|
48
|
-
expectError(new CustomTypedArgError3(1))
|
|
49
|
-
expectError(new CustomTypedArgError3(1, 2))
|
|
50
|
-
expectError(new CustomTypedArgError3('1', 2))
|
|
51
|
-
expectError(new CustomTypedArgError3(1, '2'))
|
|
52
|
-
|
|
53
|
-
const CustomTypedArgError4 = createError<string, number, [string, string]>('OTHER_CODE', 'expect %s message but got %s', 400)
|
|
54
|
-
expectError(CustomTypedArgError4('a'))
|
|
55
|
-
CustomTypedArgError4('a', 'b')
|
|
56
|
-
new CustomTypedArgError4('a', 'b')
|
|
57
|
-
expectError(CustomTypedArgError4(1))
|
|
58
|
-
expectError(new CustomTypedArgError4(1))
|
|
59
|
-
expectError(new CustomTypedArgError4(1, 2))
|
|
60
|
-
expectError(new CustomTypedArgError4('1', 2))
|
|
61
|
-
expectError(new CustomTypedArgError4(1, '2'))
|
|
62
|
-
|
|
63
|
-
const CustomTypedArgError5 = createError<[string, string, string, string]>('OTHER_CODE', 'expect %s message but got %s. Please contact %s by emailing to %s', 400)
|
|
64
|
-
expectError(CustomTypedArgError5('a'))
|
|
65
|
-
expectError(new CustomTypedArgError5('a', 'b'))
|
|
66
|
-
expectError(new CustomTypedArgError5('a', 'b', 'c'))
|
|
67
|
-
CustomTypedArgError5('a', 'b', 'c', 'd')
|
|
68
|
-
expectError(new CustomTypedArgError5('a', 'b', 'c', 'd', 'e'))
|
|
69
|
-
|
|
70
|
-
const CustomTypedArgError6 = createError<string, number, [string, string, string, string]>('OTHER_CODE', 'expect %s message but got %s. Please contact %s by emailing to %s', 400)
|
|
71
|
-
expectError(CustomTypedArgError6('a'))
|
|
72
|
-
expectError(new CustomTypedArgError6('a', 'b'))
|
|
73
|
-
expectError(new CustomTypedArgError6('a', 'b', 'c'))
|
|
74
|
-
CustomTypedArgError6('a', 'b', 'c', 'd')
|
|
75
|
-
expectError(new CustomTypedArgError6('a', 'b', 'c', 'd', 'e'))
|
|
76
|
-
|
|
77
|
-
const CustomErrorWithErrorConstructor = createError('ERROR_CODE', 'message', 500, TypeError)
|
|
78
|
-
expectType<FastifyErrorConstructor<{ code: 'ERROR_CODE', statusCode: 500 }>>(CustomErrorWithErrorConstructor)
|
|
79
|
-
CustomErrorWithErrorConstructor({ cause: new Error('Error') })
|
|
80
|
-
const customErrorWithErrorConstructor = CustomErrorWithErrorConstructor()
|
|
81
|
-
if (customErrorWithErrorConstructor instanceof FastifyError) {
|
|
82
|
-
expectType<'ERROR_CODE'>(customErrorWithErrorConstructor.code)
|
|
83
|
-
expectType<string>(customErrorWithErrorConstructor.message)
|
|
84
|
-
expectType<500>(customErrorWithErrorConstructor.statusCode)
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
const error = new FastifyError('ERROR_CODE', 'message', 500)
|
|
88
|
-
if (error instanceof FastifyError) {
|
|
89
|
-
expectType<string>(error.code)
|
|
90
|
-
expectType<string>(error.message)
|
|
91
|
-
expectType<number | undefined>(error.statusCode)
|
|
92
|
-
}
|