@fastify-utils/error 0.0.0-stage → 1.0.0

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.
@@ -0,0 +1,360 @@
1
+ //#region src/types/types.d.ts
2
+ interface HttpErrorParams {
3
+ type: string;
4
+ title: string;
5
+ status: number;
6
+ detail: string;
7
+ instance?: string;
8
+ cause?: Error;
9
+ }
10
+ interface ValidationErrors {
11
+ [field: string]: string[];
12
+ }
13
+ //#endregion
14
+ //#region src/core/http-error.d.ts
15
+ declare class HttpError extends Error {
16
+ readonly type: string;
17
+ readonly title: string;
18
+ readonly status: number;
19
+ readonly detail: string;
20
+ readonly instance?: string;
21
+ constructor(params: HttpErrorParams);
22
+ toJSON(): Record<string, unknown>;
23
+ }
24
+ //#endregion
25
+ //#region src/errors/server/internal-server-error.d.ts
26
+ declare class InternalServerError extends HttpError {
27
+ constructor(detail: unknown);
28
+ }
29
+ //#endregion
30
+ //#region src/errors/server/not-implemented-error.d.ts
31
+ declare class NotImplementedError extends HttpError {
32
+ constructor(detail: unknown);
33
+ }
34
+ //#endregion
35
+ //#region src/errors/server/bad-gateway-error.d.ts
36
+ declare class BadGatewayError extends HttpError {
37
+ readonly service?: string;
38
+ constructor(detail: unknown, service?: string);
39
+ toJSON(): Record<string, unknown>;
40
+ }
41
+ //#endregion
42
+ //#region src/errors/server/service-unavailable-error.d.ts
43
+ declare class ServiceUnavailableError extends HttpError {
44
+ readonly retryAfter?: number;
45
+ constructor(detail: unknown, retryAfter?: number);
46
+ toJSON(): Record<string, unknown>;
47
+ }
48
+ //#endregion
49
+ //#region src/errors/server/gateway-timeout-error.d.ts
50
+ declare class GatewayTimeoutError extends HttpError {
51
+ readonly service?: string;
52
+ constructor(detail: unknown, service?: string);
53
+ toJSON(): Record<string, unknown>;
54
+ }
55
+ //#endregion
56
+ //#region src/errors/server/http-version-not-supported-error.d.ts
57
+ declare class HttpVersionNotSupportedError extends HttpError {
58
+ constructor(detail: unknown);
59
+ }
60
+ //#endregion
61
+ //#region src/errors/server/variant-also-negotiates-error.d.ts
62
+ declare class VariantAlsoNegotiatesError extends HttpError {
63
+ constructor(detail: unknown);
64
+ }
65
+ //#endregion
66
+ //#region src/errors/server/insufficient-storage-error.d.ts
67
+ declare class InsufficientStorageError extends HttpError {
68
+ constructor(detail: unknown);
69
+ }
70
+ //#endregion
71
+ //#region src/errors/server/loop-detected-error.d.ts
72
+ declare class LoopDetectedError extends HttpError {
73
+ constructor(detail: unknown);
74
+ }
75
+ //#endregion
76
+ //#region src/errors/server/not-extended-error.d.ts
77
+ declare class NotExtendedError extends HttpError {
78
+ constructor(detail: unknown);
79
+ }
80
+ //#endregion
81
+ //#region src/errors/server/network-authentication-required-error.d.ts
82
+ declare class NetworkAuthenticationRequiredError extends HttpError {
83
+ constructor(detail: unknown);
84
+ }
85
+ //#endregion
86
+ //#region src/errors/client/bad-request-error.d.ts
87
+ declare class BadRequestError extends HttpError {
88
+ constructor(detail: unknown);
89
+ }
90
+ //#endregion
91
+ //#region src/errors/client/payment-required-error.d.ts
92
+ declare class PaymentRequiredError extends HttpError {
93
+ constructor(detail: unknown);
94
+ }
95
+ //#endregion
96
+ //#region src/errors/client/authentication-error.d.ts
97
+ declare class AuthenticationError extends HttpError {
98
+ constructor(detail: unknown);
99
+ }
100
+ //#endregion
101
+ //#region src/errors/client/authorization-error.d.ts
102
+ declare class AuthorizationError extends HttpError {
103
+ constructor(detail: unknown);
104
+ }
105
+ //#endregion
106
+ //#region src/errors/client/not-found-error.d.ts
107
+ declare class NotFoundError extends HttpError {
108
+ constructor(resourceOrDetail: unknown, id?: string);
109
+ }
110
+ //#endregion
111
+ //#region src/errors/client/method-not-allowed-error.d.ts
112
+ declare class MethodNotAllowedError extends HttpError {
113
+ constructor(detail: unknown);
114
+ }
115
+ //#endregion
116
+ //#region src/errors/client/not-acceptable-error.d.ts
117
+ declare class NotAcceptableError extends HttpError {
118
+ constructor(detail: unknown);
119
+ }
120
+ //#endregion
121
+ //#region src/errors/client/proxy-authentication-required-error.d.ts
122
+ declare class ProxyAuthenticationRequiredError extends HttpError {
123
+ constructor(detail: unknown);
124
+ }
125
+ //#endregion
126
+ //#region src/errors/client/request-timeout-error.d.ts
127
+ declare class RequestTimeoutError extends HttpError {
128
+ constructor(detail: unknown);
129
+ }
130
+ //#endregion
131
+ //#region src/errors/client/conflict-error.d.ts
132
+ declare class ConflictError extends HttpError {
133
+ constructor(detail: unknown);
134
+ }
135
+ //#endregion
136
+ //#region src/errors/client/gone-error.d.ts
137
+ declare class GoneError extends HttpError {
138
+ constructor(detail: unknown);
139
+ }
140
+ //#endregion
141
+ //#region src/errors/client/length-required-error.d.ts
142
+ declare class LengthRequiredError extends HttpError {
143
+ constructor(detail: unknown);
144
+ }
145
+ //#endregion
146
+ //#region src/errors/client/precondition-failed-error.d.ts
147
+ declare class PreconditionFailedError extends HttpError {
148
+ constructor(detail: unknown);
149
+ }
150
+ //#endregion
151
+ //#region src/errors/client/payload-too-large-error.d.ts
152
+ declare class PayloadTooLargeError extends HttpError {
153
+ readonly maxSize?: number;
154
+ constructor(detail: unknown, maxSize?: number);
155
+ toJSON(): Record<string, unknown>;
156
+ }
157
+ //#endregion
158
+ //#region src/errors/client/uri-too-long-error.d.ts
159
+ declare class UriTooLongError extends HttpError {
160
+ constructor(detail: unknown);
161
+ }
162
+ //#endregion
163
+ //#region src/errors/client/unsupported-media-type-error.d.ts
164
+ declare class UnsupportedMediaTypeError extends HttpError {
165
+ constructor(detail: unknown);
166
+ }
167
+ //#endregion
168
+ //#region src/errors/client/range-not-satisfiable-error.d.ts
169
+ declare class RangeNotSatisfiableError extends HttpError {
170
+ constructor(detail: unknown);
171
+ }
172
+ //#endregion
173
+ //#region src/errors/client/expectation-failed-error.d.ts
174
+ declare class ExpectationFailedError extends HttpError {
175
+ constructor(detail: unknown);
176
+ }
177
+ //#endregion
178
+ //#region src/errors/client/misdirected-request-error.d.ts
179
+ declare class MisdirectedRequestError extends HttpError {
180
+ constructor(detail: unknown);
181
+ }
182
+ //#endregion
183
+ //#region src/errors/client/validation-error.d.ts
184
+ declare class ValidationError extends HttpError {
185
+ readonly validationErrors?: ValidationErrors;
186
+ constructor(detail: unknown, validationErrors?: ValidationErrors);
187
+ toJSON(): Record<string, unknown>;
188
+ }
189
+ //#endregion
190
+ //#region src/errors/client/locked-error.d.ts
191
+ declare class LockedError extends HttpError {
192
+ constructor(detail: unknown);
193
+ }
194
+ //#endregion
195
+ //#region src/errors/client/failed-dependency-error.d.ts
196
+ declare class FailedDependencyError extends HttpError {
197
+ constructor(detail: unknown);
198
+ }
199
+ //#endregion
200
+ //#region src/errors/client/too-early-error.d.ts
201
+ declare class TooEarlyError extends HttpError {
202
+ constructor(detail: unknown);
203
+ }
204
+ //#endregion
205
+ //#region src/errors/client/upgrade-required-error.d.ts
206
+ declare class UpgradeRequiredError extends HttpError {
207
+ constructor(detail: unknown);
208
+ }
209
+ //#endregion
210
+ //#region src/errors/client/precondition-required-error.d.ts
211
+ declare class PreconditionRequiredError extends HttpError {
212
+ constructor(detail: unknown);
213
+ }
214
+ //#endregion
215
+ //#region src/errors/client/rate-limit-error.d.ts
216
+ declare class RateLimitError extends HttpError {
217
+ readonly retryAfter?: number;
218
+ constructor(detail: unknown, retryAfter?: number);
219
+ toJSON(): Record<string, unknown>;
220
+ }
221
+ //#endregion
222
+ //#region src/errors/client/request-header-fields-too-large-error.d.ts
223
+ declare class RequestHeaderFieldsTooLargeError extends HttpError {
224
+ constructor(detail: unknown);
225
+ }
226
+ //#endregion
227
+ //#region src/errors/client/unavailable-for-legal-reasons-error.d.ts
228
+ declare class UnavailableForLegalReasonsError extends HttpError {
229
+ constructor(detail: unknown);
230
+ }
231
+ //#endregion
232
+ //#region src/error.d.ts
233
+ export declare const error: {
234
+ internal: (detail: unknown) => InternalServerError;
235
+ notImplemented: (detail: unknown) => NotImplementedError;
236
+ badGateway: (detail: unknown, service?: string) => BadGatewayError;
237
+ serviceUnavailable: (detail: unknown, retryAfter?: number) => ServiceUnavailableError;
238
+ gatewayTimeout: (detail: unknown, service?: string) => GatewayTimeoutError;
239
+ httpVersionNotSupported: (detail: unknown) => HttpVersionNotSupportedError;
240
+ variantAlsoNegotiates: (detail: unknown) => VariantAlsoNegotiatesError;
241
+ insufficientStorage: (detail: unknown) => InsufficientStorageError;
242
+ loopDetected: (detail: unknown) => LoopDetectedError;
243
+ notExtended: (detail: unknown) => NotExtendedError;
244
+ networkAuthenticationRequired: (detail: unknown) => NetworkAuthenticationRequiredError;
245
+ db: (detail: unknown) => ServiceUnavailableError;
246
+ fetch: (detail: unknown, service?: string) => BadGatewayError;
247
+ envNotSet: (detail: unknown) => NotImplementedError;
248
+ envInvalid: (detail: unknown) => NotImplementedError;
249
+ maintenance: (detail: unknown, retryAfter?: number) => ServiceUnavailableError;
250
+ migration: (detail: unknown) => InsufficientStorageError;
251
+ unhandledRejection: (detail: unknown) => InternalServerError;
252
+ uncaughtException: (detail: unknown) => InternalServerError;
253
+ badRequest: (detail: unknown) => BadRequestError;
254
+ paymentRequired: (detail: unknown) => PaymentRequiredError;
255
+ authentication: (detail: unknown) => AuthenticationError;
256
+ authorization: (detail: unknown) => AuthorizationError;
257
+ notFound: (resourceOrDetail: unknown, id?: string) => NotFoundError;
258
+ methodNotAllowed: (detail: unknown) => MethodNotAllowedError;
259
+ notAcceptable: (detail: unknown) => NotAcceptableError;
260
+ proxyAuthenticationRequired: (detail: unknown) => ProxyAuthenticationRequiredError;
261
+ requestTimeout: (detail: unknown) => RequestTimeoutError;
262
+ conflict: (detail: unknown) => ConflictError;
263
+ gone: (detail: unknown) => GoneError;
264
+ lengthRequired: (detail: unknown) => LengthRequiredError;
265
+ preconditionFailed: (detail: unknown) => PreconditionFailedError;
266
+ payloadTooLarge: (detail: unknown, maxSize?: number) => PayloadTooLargeError;
267
+ uriTooLong: (detail: unknown) => UriTooLongError;
268
+ unsupportedMediaType: (detail: unknown) => UnsupportedMediaTypeError;
269
+ rangeNotSatisfiable: (detail: unknown) => RangeNotSatisfiableError;
270
+ expectationFailed: (detail: unknown) => ExpectationFailedError;
271
+ misdirectedRequest: (detail: unknown) => MisdirectedRequestError;
272
+ validation: (detail: unknown, validationErrors?: ValidationErrors) => ValidationError;
273
+ locked: (detail: unknown) => LockedError;
274
+ failedDependency: (detail: unknown) => FailedDependencyError;
275
+ tooEarly: (detail: unknown) => TooEarlyError;
276
+ upgradeRequired: (detail: unknown) => UpgradeRequiredError;
277
+ preconditionRequired: (detail: unknown) => PreconditionRequiredError;
278
+ rateLimit: (detail: unknown, retryAfter?: number) => RateLimitError;
279
+ requestHeaderFieldsTooLarge: (detail: unknown) => RequestHeaderFieldsTooLargeError;
280
+ unavailableForLegalReasons: (detail: unknown) => UnavailableForLegalReasonsError;
281
+ validate: (detail: unknown, validationErrors?: ValidationErrors) => ValidationError;
282
+ permission: (detail: unknown) => AuthorizationError;
283
+ access: (detail: unknown) => AuthorizationError;
284
+ idNotFound: (resourceOrDetail: unknown, id?: string) => NotFoundError;
285
+ duplicate: (detail: unknown) => ConflictError;
286
+ thirdParty: (detail: unknown) => FailedDependencyError;
287
+ };
288
+ //#endregion
289
+ //#region src/helpers/create-error-by-status/index.d.ts
290
+ declare const createErrorByStatus: (status: number, detail: unknown) => HttpError;
291
+ //#endregion
292
+ //#region src/helpers/is-http-error/index.d.ts
293
+ export declare function isHttpError(error: unknown): error is HttpError;
294
+ //#endregion
295
+ //#region src/helpers/is-valid-rfc9457-json/index.d.ts
296
+ export declare const isValidRFC9457Json: (data: unknown) => boolean;
297
+ //#endregion
298
+ //#region src/errors.d.ts
299
+ export declare const errors: {
300
+ client: {
301
+ badRequest: (detail: unknown) => BadRequestError;
302
+ paymentRequired: (detail: unknown) => PaymentRequiredError;
303
+ authentication: (detail: unknown) => AuthenticationError;
304
+ authorization: (detail: unknown) => AuthorizationError;
305
+ notFound: (resourceOrDetail: unknown, id?: string) => NotFoundError;
306
+ methodNotAllowed: (detail: unknown) => MethodNotAllowedError;
307
+ notAcceptable: (detail: unknown) => NotAcceptableError;
308
+ proxyAuthenticationRequired: (detail: unknown) => ProxyAuthenticationRequiredError;
309
+ requestTimeout: (detail: unknown) => RequestTimeoutError;
310
+ conflict: (detail: unknown) => ConflictError;
311
+ gone: (detail: unknown) => GoneError;
312
+ lengthRequired: (detail: unknown) => LengthRequiredError;
313
+ preconditionFailed: (detail: unknown) => PreconditionFailedError;
314
+ payloadTooLarge: (detail: unknown, maxSize?: number) => PayloadTooLargeError;
315
+ uriTooLong: (detail: unknown) => UriTooLongError;
316
+ unsupportedMediaType: (detail: unknown) => UnsupportedMediaTypeError;
317
+ rangeNotSatisfiable: (detail: unknown) => RangeNotSatisfiableError;
318
+ expectationFailed: (detail: unknown) => ExpectationFailedError;
319
+ misdirectedRequest: (detail: unknown) => MisdirectedRequestError;
320
+ validation: (detail: unknown, validationErrors?: ValidationErrors) => ValidationError;
321
+ locked: (detail: unknown) => LockedError;
322
+ failedDependency: (detail: unknown) => FailedDependencyError;
323
+ tooEarly: (detail: unknown) => TooEarlyError;
324
+ upgradeRequired: (detail: unknown) => UpgradeRequiredError;
325
+ preconditionRequired: (detail: unknown) => PreconditionRequiredError;
326
+ rateLimit: (detail: unknown, retryAfter?: number) => RateLimitError;
327
+ requestHeaderFieldsTooLarge: (detail: unknown) => RequestHeaderFieldsTooLargeError;
328
+ unavailableForLegalReasons: (detail: unknown) => UnavailableForLegalReasonsError;
329
+ validate: (detail: unknown, validationErrors?: ValidationErrors) => ValidationError;
330
+ permission: (detail: unknown) => AuthorizationError;
331
+ access: (detail: unknown) => AuthorizationError;
332
+ idNotFound: (resourceOrDetail: unknown, id?: string) => NotFoundError;
333
+ duplicate: (detail: unknown) => ConflictError;
334
+ thirdParty: (detail: unknown) => FailedDependencyError;
335
+ };
336
+ server: {
337
+ internal: (detail: unknown) => InternalServerError;
338
+ notImplemented: (detail: unknown) => NotImplementedError;
339
+ badGateway: (detail: unknown, service?: string) => BadGatewayError;
340
+ serviceUnavailable: (detail: unknown, retryAfter?: number) => ServiceUnavailableError;
341
+ gatewayTimeout: (detail: unknown, service?: string) => GatewayTimeoutError;
342
+ httpVersionNotSupported: (detail: unknown) => HttpVersionNotSupportedError;
343
+ variantAlsoNegotiates: (detail: unknown) => VariantAlsoNegotiatesError;
344
+ insufficientStorage: (detail: unknown) => InsufficientStorageError;
345
+ loopDetected: (detail: unknown) => LoopDetectedError;
346
+ notExtended: (detail: unknown) => NotExtendedError;
347
+ networkAuthenticationRequired: (detail: unknown) => NetworkAuthenticationRequiredError;
348
+ db: (detail: unknown) => ServiceUnavailableError;
349
+ fetch: (detail: unknown, service?: string) => BadGatewayError;
350
+ envNotSet: (detail: unknown) => NotImplementedError;
351
+ envInvalid: (detail: unknown) => NotImplementedError;
352
+ maintenance: (detail: unknown, retryAfter?: number) => ServiceUnavailableError;
353
+ migration: (detail: unknown) => InsufficientStorageError;
354
+ unhandledRejection: (detail: unknown) => InternalServerError;
355
+ uncaughtException: (detail: unknown) => InternalServerError;
356
+ };
357
+ byStatus: typeof createErrorByStatus;
358
+ };
359
+ //#endregion
360
+ export type { ValidationErrors };