@geekmidas/errors 0.0.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/dist/index.cjs ADDED
@@ -0,0 +1,586 @@
1
+
2
+ //#region src/index.ts
3
+ /**
4
+ * Base HTTP Error class that extends the native Error.
5
+ * Provides a foundation for all HTTP-specific errors with status codes and structured error responses.
6
+ *
7
+ * @extends Error
8
+ *
9
+ * @example
10
+ * ```typescript
11
+ * throw new HttpError(400, 'Bad Request', {
12
+ * details: { field: 'email', message: 'Invalid format' }
13
+ * });
14
+ * ```
15
+ */
16
+ var HttpError = class extends Error {
17
+ /** The HTTP status code (e.g., 400, 404, 500) */
18
+ statusCode;
19
+ /** The standard HTTP status message (e.g., 'Bad Request', 'Not Found') */
20
+ statusMessage;
21
+ /** Type discriminator for runtime type checking */
22
+ isHttpError = true;
23
+ /** Additional error details for debugging or client information */
24
+ details;
25
+ /** Application-specific error code for client-side handling */
26
+ code;
27
+ /**
28
+ * Creates a new HttpError instance.
29
+ *
30
+ * @param statusCode - The HTTP status code
31
+ * @param message - Optional error message for the client
32
+ * @param options - Optional configuration object
33
+ * @param options.statusMessage - Override the default status message
34
+ * @param options.details - Additional error details or context
35
+ * @param options.code - Application-specific error code
36
+ * @param options.cause - The underlying error that caused this error (ES2022)
37
+ */
38
+ constructor(statusCode, message, options) {
39
+ super(message || options?.statusMessage || "HTTP Error");
40
+ this.name = this.constructor.name;
41
+ this.statusCode = statusCode;
42
+ this.statusMessage = options?.statusMessage || this.getDefaultStatusMessage(statusCode);
43
+ this.details = options?.details;
44
+ this.code = options?.code;
45
+ if (options?.cause) this.cause = options.cause;
46
+ Error.captureStackTrace(this, this.constructor);
47
+ }
48
+ /**
49
+ * Gets the error response body as a JSON string.
50
+ * Used for sending the error response to clients.
51
+ *
52
+ * @returns JSON string containing message, code, and error details
53
+ */
54
+ get body() {
55
+ return JSON.stringify({
56
+ message: this.message,
57
+ code: this.code,
58
+ error: this.details
59
+ });
60
+ }
61
+ /**
62
+ * Gets the default HTTP status message for a given status code.
63
+ *
64
+ * @param statusCode - The HTTP status code
65
+ * @returns The standard HTTP status message or 'Unknown Error' if not found
66
+ * @private
67
+ */
68
+ getDefaultStatusMessage(statusCode) {
69
+ const statusMessages = {
70
+ 400: "Bad Request",
71
+ 401: "Unauthorized",
72
+ 403: "Forbidden",
73
+ 404: "Not Found",
74
+ 405: "Method Not Allowed",
75
+ 406: "Not Acceptable",
76
+ 408: "Request Timeout",
77
+ 409: "Conflict",
78
+ 410: "Gone",
79
+ 422: "Unprocessable Entity",
80
+ 429: "Too Many Requests",
81
+ 500: "Internal Server Error",
82
+ 501: "Not Implemented",
83
+ 502: "Bad Gateway",
84
+ 503: "Service Unavailable",
85
+ 504: "Gateway Timeout"
86
+ };
87
+ return statusMessages[statusCode] || "Unknown Error";
88
+ }
89
+ /**
90
+ * Serializes the error to a JSON-compatible object.
91
+ * Useful for logging and debugging purposes.
92
+ *
93
+ * @returns Object representation of the error including stack trace
94
+ */
95
+ toJSON() {
96
+ return {
97
+ name: this.name,
98
+ message: this.message,
99
+ statusCode: this.statusCode,
100
+ statusMessage: this.statusMessage,
101
+ code: this.code,
102
+ details: this.details,
103
+ stack: this.stack
104
+ };
105
+ }
106
+ };
107
+ /**
108
+ * Represents a 400 Bad Request error.
109
+ * Used when the client sends a malformed or invalid request.
110
+ *
111
+ * @extends HttpError
112
+ *
113
+ * @example
114
+ * ```typescript
115
+ * throw new BadRequestError('Invalid JSON', { line: 5, column: 12 });
116
+ * ```
117
+ */
118
+ var BadRequestError = class extends HttpError {
119
+ constructor(message, details) {
120
+ super(400, message, { details });
121
+ }
122
+ };
123
+ /**
124
+ * Represents a 401 Unauthorized error.
125
+ * Used when authentication is required but not provided or invalid.
126
+ *
127
+ * @extends HttpError
128
+ *
129
+ * @example
130
+ * ```typescript
131
+ * throw new UnauthorizedError('Invalid token');
132
+ * ```
133
+ */
134
+ var UnauthorizedError = class extends HttpError {
135
+ constructor(message, details) {
136
+ super(401, message, { details });
137
+ }
138
+ };
139
+ /**
140
+ * Represents a 403 Forbidden error.
141
+ * Used when the client is authenticated but lacks permission for the resource.
142
+ *
143
+ * @extends HttpError
144
+ *
145
+ * @example
146
+ * ```typescript
147
+ * throw new ForbiddenError('Insufficient permissions', { required: 'admin' });
148
+ * ```
149
+ */
150
+ var ForbiddenError = class extends HttpError {
151
+ constructor(message, details) {
152
+ super(403, message, { details });
153
+ }
154
+ };
155
+ /**
156
+ * Represents a 404 Not Found error.
157
+ * Used when the requested resource doesn't exist.
158
+ *
159
+ * @extends HttpError
160
+ *
161
+ * @example
162
+ * ```typescript
163
+ * throw new NotFoundError('User not found', { userId: '123' });
164
+ * ```
165
+ */
166
+ var NotFoundError = class extends HttpError {
167
+ constructor(message, details) {
168
+ super(404, message, { details });
169
+ }
170
+ };
171
+ /**
172
+ * Represents a 405 Method Not Allowed error.
173
+ * Used when the HTTP method is not supported for the requested resource.
174
+ *
175
+ * @extends HttpError
176
+ *
177
+ * @example
178
+ * ```typescript
179
+ * throw new MethodNotAllowedError('DELETE not supported', ['GET', 'POST', 'PUT']);
180
+ * ```
181
+ */
182
+ var MethodNotAllowedError = class extends HttpError {
183
+ /**
184
+ * @param message - Optional error message
185
+ * @param allowedMethods - Array of allowed HTTP methods for this resource
186
+ */
187
+ constructor(message, allowedMethods) {
188
+ super(405, message, { details: allowedMethods ? { allowedMethods } : void 0 });
189
+ }
190
+ };
191
+ /**
192
+ * Represents a 409 Conflict error.
193
+ * Used when the request conflicts with the current state of the resource.
194
+ *
195
+ * @extends HttpError
196
+ *
197
+ * @example
198
+ * ```typescript
199
+ * throw new ConflictError('Email already exists', { email: 'user@example.com' });
200
+ * ```
201
+ */
202
+ var ConflictError = class extends HttpError {
203
+ constructor(message, details) {
204
+ super(409, message, { details });
205
+ }
206
+ };
207
+ /**
208
+ * Represents a 422 Unprocessable Entity error.
209
+ * Used when the request is well-formed but contains semantic errors.
210
+ *
211
+ * @extends HttpError
212
+ *
213
+ * @example
214
+ * ```typescript
215
+ * throw new UnprocessableEntityError('Validation failed', {
216
+ * email: 'Invalid format',
217
+ * age: 'Must be 18 or older'
218
+ * });
219
+ * ```
220
+ */
221
+ var UnprocessableEntityError = class extends HttpError {
222
+ /**
223
+ * @param message - Optional error message
224
+ * @param validationErrors - Object containing field-specific validation errors
225
+ */
226
+ constructor(message, validationErrors) {
227
+ super(422, message, { details: validationErrors ? { validationErrors } : void 0 });
228
+ }
229
+ };
230
+ /**
231
+ * Represents a 429 Too Many Requests error.
232
+ * Used when the client has exceeded rate limits.
233
+ *
234
+ * @extends HttpError
235
+ *
236
+ * @example
237
+ * ```typescript
238
+ * throw new TooManyRequestsError('Rate limit exceeded', 60); // retry after 60 seconds
239
+ * ```
240
+ */
241
+ var TooManyRequestsError = class extends HttpError {
242
+ /**
243
+ * @param message - Optional error message
244
+ * @param retryAfter - Number of seconds the client should wait before retrying
245
+ */
246
+ constructor(message, retryAfter) {
247
+ super(429, message, { details: retryAfter ? { retryAfter } : void 0 });
248
+ }
249
+ };
250
+ /**
251
+ * Represents a 500 Internal Server Error.
252
+ * Used for unexpected server-side errors.
253
+ *
254
+ * @extends HttpError
255
+ *
256
+ * @example
257
+ * ```typescript
258
+ * throw new InternalServerError('Database connection failed');
259
+ * ```
260
+ */
261
+ var InternalServerError = class extends HttpError {
262
+ constructor(message, details) {
263
+ super(500, message, { details });
264
+ }
265
+ };
266
+ /**
267
+ * Represents a 501 Not Implemented error.
268
+ * Used when the server doesn't support the requested functionality.
269
+ *
270
+ * @extends HttpError
271
+ *
272
+ * @example
273
+ * ```typescript
274
+ * throw new NotImplementedError('WebSocket support not implemented');
275
+ * ```
276
+ */
277
+ var NotImplementedError = class extends HttpError {
278
+ constructor(message, details) {
279
+ super(501, message, { details });
280
+ }
281
+ };
282
+ /**
283
+ * Represents a 502 Bad Gateway error.
284
+ * Used when the server receives an invalid response from an upstream server.
285
+ *
286
+ * @extends HttpError
287
+ *
288
+ * @example
289
+ * ```typescript
290
+ * throw new BadGatewayError('Upstream server error');
291
+ * ```
292
+ */
293
+ var BadGatewayError = class extends HttpError {
294
+ constructor(message, details) {
295
+ super(502, message, { details });
296
+ }
297
+ };
298
+ /**
299
+ * Represents a 503 Service Unavailable error.
300
+ * Used when the server is temporarily unable to handle requests.
301
+ *
302
+ * @extends HttpError
303
+ *
304
+ * @example
305
+ * ```typescript
306
+ * throw new ServiceUnavailableError('Maintenance in progress', 300); // retry after 5 minutes
307
+ * ```
308
+ */
309
+ var ServiceUnavailableError = class extends HttpError {
310
+ /**
311
+ * @param message - Optional error message
312
+ * @param retryAfter - Number of seconds the client should wait before retrying
313
+ */
314
+ constructor(message, retryAfter) {
315
+ super(503, message, { details: retryAfter ? { retryAfter } : void 0 });
316
+ }
317
+ };
318
+ /**
319
+ * Represents a 504 Gateway Timeout error.
320
+ * Used when the server doesn't receive a timely response from an upstream server.
321
+ *
322
+ * @extends HttpError
323
+ *
324
+ * @example
325
+ * ```typescript
326
+ * throw new GatewayTimeoutError('Upstream server timeout');
327
+ * ```
328
+ */
329
+ var GatewayTimeoutError = class extends HttpError {
330
+ constructor(message, details) {
331
+ super(504, message, { details });
332
+ }
333
+ };
334
+ /** Type-safe error registry mapping status codes to their factory functions */
335
+ const errorRegistry = {
336
+ 400: {
337
+ type: "standard",
338
+ factory: (m, d) => new BadRequestError(m, d)
339
+ },
340
+ 401: {
341
+ type: "standard",
342
+ factory: (m, d) => new UnauthorizedError(m, d)
343
+ },
344
+ 403: {
345
+ type: "standard",
346
+ factory: (m, d) => new ForbiddenError(m, d)
347
+ },
348
+ 404: {
349
+ type: "standard",
350
+ factory: (m, d) => new NotFoundError(m, d)
351
+ },
352
+ 405: {
353
+ type: "methodNotAllowed",
354
+ factory: (m, am) => new MethodNotAllowedError(m, am)
355
+ },
356
+ 409: {
357
+ type: "standard",
358
+ factory: (m, d) => new ConflictError(m, d)
359
+ },
360
+ 422: {
361
+ type: "validation",
362
+ factory: (m, ve) => new UnprocessableEntityError(m, ve)
363
+ },
364
+ 429: {
365
+ type: "retryAfter",
366
+ factory: (m, ra) => new TooManyRequestsError(m, ra)
367
+ },
368
+ 500: {
369
+ type: "standard",
370
+ factory: (m, d) => new InternalServerError(m, d)
371
+ },
372
+ 501: {
373
+ type: "standard",
374
+ factory: (m, d) => new NotImplementedError(m, d)
375
+ },
376
+ 502: {
377
+ type: "standard",
378
+ factory: (m, d) => new BadGatewayError(m, d)
379
+ },
380
+ 503: {
381
+ type: "retryAfter",
382
+ factory: (m, ra) => new ServiceUnavailableError(m, ra)
383
+ },
384
+ 504: {
385
+ type: "standard",
386
+ factory: (m, d) => new GatewayTimeoutError(m, d)
387
+ }
388
+ };
389
+ /** Handler functions for each factory type */
390
+ const factoryHandlers = {
391
+ standard: (entry, message, options) => entry.factory(message, options?.details),
392
+ methodNotAllowed: (entry, message, options) => entry.factory(message, options?.allowedMethods),
393
+ retryAfter: (entry, message, options) => entry.factory(message, options?.retryAfter),
394
+ validation: (entry, message, options) => entry.factory(message, options?.validationErrors)
395
+ };
396
+ function createHttpError(statusCode, message, options) {
397
+ const entry = errorRegistry[statusCode];
398
+ if (entry) {
399
+ const handler = factoryHandlers[entry.type];
400
+ return handler(entry, message, options);
401
+ }
402
+ return new HttpError(statusCode, message, options);
403
+ }
404
+ /**
405
+ * Type-safe error creation utilities with descriptive method names.
406
+ * Provides a fluent API for creating specific HTTP errors.
407
+ *
408
+ * @example
409
+ * ```typescript
410
+ * createError.notFound('User not found');
411
+ * createError.badRequest('Invalid input', { field: 'email' });
412
+ * createError.methodNotAllowed('DELETE not supported', ['GET', 'POST']);
413
+ * ```
414
+ */
415
+ const createError = {
416
+ badRequest: (message, details) => new BadRequestError(message, details),
417
+ unauthorized: (message, details) => new UnauthorizedError(message, details),
418
+ forbidden: (message, details) => new ForbiddenError(message, details),
419
+ notFound: (message, details) => new NotFoundError(message, details),
420
+ methodNotAllowed: (message, allowedMethods) => new MethodNotAllowedError(message, allowedMethods),
421
+ conflict: (message, details) => new ConflictError(message, details),
422
+ unprocessableEntity: (message, validationErrors) => new UnprocessableEntityError(message, validationErrors),
423
+ tooManyRequests: (message, retryAfter) => new TooManyRequestsError(message, retryAfter),
424
+ internalServerError: (message, details) => new InternalServerError(message, details),
425
+ notImplemented: (message, details) => new NotImplementedError(message, details),
426
+ badGateway: (message, details) => new BadGatewayError(message, details),
427
+ serviceUnavailable: (message, retryAfter) => new ServiceUnavailableError(message, retryAfter),
428
+ gatewayTimeout: (message, details) => new GatewayTimeoutError(message, details)
429
+ };
430
+ /**
431
+ * Type guard to check if an error is an HttpError.
432
+ * Works with both instanceof checks and duck typing.
433
+ *
434
+ * @param error - The error to check
435
+ * @returns True if the error is an HttpError
436
+ *
437
+ * @example
438
+ * ```typescript
439
+ * try {
440
+ * // some code
441
+ * } catch (error) {
442
+ * if (isHttpError(error)) {
443
+ * console.log(`HTTP ${error.statusCode}: ${error.message}`);
444
+ * }
445
+ * }
446
+ * ```
447
+ */
448
+ function isHttpError(error) {
449
+ return error instanceof HttpError || error !== null && typeof error === "object" && "isHttpError" in error && error.isHttpError === true;
450
+ }
451
+ /**
452
+ * Type guard to check if an error is a client error (4xx status code).
453
+ *
454
+ * @param error - The error to check
455
+ * @returns True if the error is an HttpError with a 4xx status code
456
+ *
457
+ * @example
458
+ * ```typescript
459
+ * if (isClientError(error)) {
460
+ * // Log client error metrics
461
+ * }
462
+ * ```
463
+ */
464
+ function isClientError(error) {
465
+ return isHttpError(error) && error.statusCode >= 400 && error.statusCode < 500;
466
+ }
467
+ /**
468
+ * Type guard to check if an error is a server error (5xx status code).
469
+ *
470
+ * @param error - The error to check
471
+ * @returns True if the error is an HttpError with a 5xx status code
472
+ *
473
+ * @example
474
+ * ```typescript
475
+ * if (isServerError(error)) {
476
+ * // Trigger alerts for server errors
477
+ * }
478
+ * ```
479
+ */
480
+ function isServerError(error) {
481
+ return isHttpError(error) && error.statusCode >= 500 && error.statusCode < 600;
482
+ }
483
+ /**
484
+ * Wraps an unknown error into an HttpError.
485
+ * If the error is already an HttpError, returns it unchanged.
486
+ *
487
+ * @param error - The error to wrap
488
+ * @param statusCode - The HTTP status code to use (defaults to 500)
489
+ * @param message - Optional message to override the original error message
490
+ * @returns An HttpError instance
491
+ *
492
+ * @example
493
+ * ```typescript
494
+ * try {
495
+ * await someOperation();
496
+ * } catch (error) {
497
+ * throw wrapError(error, 503, 'Service temporarily unavailable');
498
+ * }
499
+ * ```
500
+ */
501
+ function wrapError(error, statusCode = 500, message) {
502
+ if (isHttpError(error)) return error;
503
+ if (error instanceof HttpError) return error;
504
+ return new HttpError(statusCode, message || "An unknown error occurred", { details: { originalError: error } });
505
+ }
506
+ /**
507
+ * HTTP status code enum for type-safe status code usage.
508
+ * Includes common 2xx, 3xx, 4xx, and 5xx status codes.
509
+ */
510
+ let HttpStatusCode = /* @__PURE__ */ function(HttpStatusCode$1) {
511
+ HttpStatusCode$1[HttpStatusCode$1["OK"] = 200] = "OK";
512
+ HttpStatusCode$1[HttpStatusCode$1["CREATED"] = 201] = "CREATED";
513
+ HttpStatusCode$1[HttpStatusCode$1["ACCEPTED"] = 202] = "ACCEPTED";
514
+ HttpStatusCode$1[HttpStatusCode$1["NO_CONTENT"] = 204] = "NO_CONTENT";
515
+ HttpStatusCode$1[HttpStatusCode$1["MOVED_PERMANENTLY"] = 301] = "MOVED_PERMANENTLY";
516
+ HttpStatusCode$1[HttpStatusCode$1["FOUND"] = 302] = "FOUND";
517
+ HttpStatusCode$1[HttpStatusCode$1["NOT_MODIFIED"] = 304] = "NOT_MODIFIED";
518
+ HttpStatusCode$1[HttpStatusCode$1["BAD_REQUEST"] = 400] = "BAD_REQUEST";
519
+ HttpStatusCode$1[HttpStatusCode$1["UNAUTHORIZED"] = 401] = "UNAUTHORIZED";
520
+ HttpStatusCode$1[HttpStatusCode$1["FORBIDDEN"] = 403] = "FORBIDDEN";
521
+ HttpStatusCode$1[HttpStatusCode$1["NOT_FOUND"] = 404] = "NOT_FOUND";
522
+ HttpStatusCode$1[HttpStatusCode$1["METHOD_NOT_ALLOWED"] = 405] = "METHOD_NOT_ALLOWED";
523
+ HttpStatusCode$1[HttpStatusCode$1["NOT_ACCEPTABLE"] = 406] = "NOT_ACCEPTABLE";
524
+ HttpStatusCode$1[HttpStatusCode$1["REQUEST_TIMEOUT"] = 408] = "REQUEST_TIMEOUT";
525
+ HttpStatusCode$1[HttpStatusCode$1["CONFLICT"] = 409] = "CONFLICT";
526
+ HttpStatusCode$1[HttpStatusCode$1["GONE"] = 410] = "GONE";
527
+ HttpStatusCode$1[HttpStatusCode$1["UNPROCESSABLE_ENTITY"] = 422] = "UNPROCESSABLE_ENTITY";
528
+ HttpStatusCode$1[HttpStatusCode$1["TOO_MANY_REQUESTS"] = 429] = "TOO_MANY_REQUESTS";
529
+ HttpStatusCode$1[HttpStatusCode$1["INTERNAL_SERVER_ERROR"] = 500] = "INTERNAL_SERVER_ERROR";
530
+ HttpStatusCode$1[HttpStatusCode$1["NOT_IMPLEMENTED"] = 501] = "NOT_IMPLEMENTED";
531
+ HttpStatusCode$1[HttpStatusCode$1["BAD_GATEWAY"] = 502] = "BAD_GATEWAY";
532
+ HttpStatusCode$1[HttpStatusCode$1["SERVICE_UNAVAILABLE"] = 503] = "SERVICE_UNAVAILABLE";
533
+ HttpStatusCode$1[HttpStatusCode$1["GATEWAY_TIMEOUT"] = 504] = "GATEWAY_TIMEOUT";
534
+ return HttpStatusCode$1;
535
+ }({});
536
+ /**
537
+ * Namespace containing all HTTP error classes.
538
+ * Useful for importing all error types at once.
539
+ *
540
+ * @example
541
+ * ```typescript
542
+ * import { HttpErrors } from '@geekmidas/errors';
543
+ * throw new HttpErrors.NotFoundError('Resource not found');
544
+ * ```
545
+ */
546
+ const HttpErrors = {
547
+ HttpError,
548
+ BadRequestError,
549
+ UnauthorizedError,
550
+ ForbiddenError,
551
+ NotFoundError,
552
+ MethodNotAllowedError,
553
+ ConflictError,
554
+ UnprocessableEntityError,
555
+ TooManyRequestsError,
556
+ InternalServerError,
557
+ NotImplementedError,
558
+ BadGatewayError,
559
+ ServiceUnavailableError,
560
+ GatewayTimeoutError
561
+ };
562
+
563
+ //#endregion
564
+ exports.BadGatewayError = BadGatewayError;
565
+ exports.BadRequestError = BadRequestError;
566
+ exports.ConflictError = ConflictError;
567
+ exports.ForbiddenError = ForbiddenError;
568
+ exports.GatewayTimeoutError = GatewayTimeoutError;
569
+ exports.HttpError = HttpError;
570
+ exports.HttpErrors = HttpErrors;
571
+ exports.HttpStatusCode = HttpStatusCode;
572
+ exports.InternalServerError = InternalServerError;
573
+ exports.MethodNotAllowedError = MethodNotAllowedError;
574
+ exports.NotFoundError = NotFoundError;
575
+ exports.NotImplementedError = NotImplementedError;
576
+ exports.ServiceUnavailableError = ServiceUnavailableError;
577
+ exports.TooManyRequestsError = TooManyRequestsError;
578
+ exports.UnauthorizedError = UnauthorizedError;
579
+ exports.UnprocessableEntityError = UnprocessableEntityError;
580
+ exports.createError = createError;
581
+ exports.createHttpError = createHttpError;
582
+ exports.isClientError = isClientError;
583
+ exports.isHttpError = isHttpError;
584
+ exports.isServerError = isServerError;
585
+ exports.wrapError = wrapError;
586
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.cjs","names":["statusCode: number","message?: string","options?: {\n statusMessage?: string;\n details?: any;\n code?: string;\n cause?: Error;\n }","statusMessages: Record<number, string>","details?: any","allowedMethods?: string[]","validationErrors?: any","retryAfter?: number","m: string","d: any","am: string[]","ve: any","ra: number","factoryHandlers: Record<\n ErrorFactory['type'],\n (entry: any, message?: string, options?: any) => HttpError\n>","options?: any","error: unknown"],"sources":["../src/index.ts"],"sourcesContent":["// http-errors.ts - Core HTTP Error Classes and Types\n\n/**\n * Base HTTP Error class that extends the native Error.\n * Provides a foundation for all HTTP-specific errors with status codes and structured error responses.\n *\n * @extends Error\n *\n * @example\n * ```typescript\n * throw new HttpError(400, 'Bad Request', {\n * details: { field: 'email', message: 'Invalid format' }\n * });\n * ```\n */\nexport class HttpError extends Error {\n /** The HTTP status code (e.g., 400, 404, 500) */\n public readonly statusCode: number;\n /** The standard HTTP status message (e.g., 'Bad Request', 'Not Found') */\n public readonly statusMessage: string;\n /** Type discriminator for runtime type checking */\n public readonly isHttpError = true;\n /** Additional error details for debugging or client information */\n public readonly details?: any;\n /** Application-specific error code for client-side handling */\n public readonly code?: string;\n\n /**\n * Creates a new HttpError instance.\n *\n * @param statusCode - The HTTP status code\n * @param message - Optional error message for the client\n * @param options - Optional configuration object\n * @param options.statusMessage - Override the default status message\n * @param options.details - Additional error details or context\n * @param options.code - Application-specific error code\n * @param options.cause - The underlying error that caused this error (ES2022)\n */\n constructor(\n statusCode: number,\n message?: string,\n options?: {\n statusMessage?: string;\n details?: any;\n code?: string;\n cause?: Error;\n },\n ) {\n super(message || options?.statusMessage || 'HTTP Error');\n this.name = this.constructor.name;\n this.statusCode = statusCode;\n this.statusMessage =\n options?.statusMessage || this.getDefaultStatusMessage(statusCode);\n this.details = options?.details;\n this.code = options?.code;\n\n // Set cause if provided (ES2022 feature)\n if (options?.cause) {\n this.cause = options.cause;\n }\n // @ts-ignore\n // Maintains proper stack trace for where our error was thrown\n Error.captureStackTrace(this, this.constructor);\n }\n\n /**\n * Gets the error response body as a JSON string.\n * Used for sending the error response to clients.\n *\n * @returns JSON string containing message, code, and error details\n */\n get body() {\n return JSON.stringify({\n message: this.message,\n code: this.code,\n error: this.details,\n });\n }\n\n /**\n * Gets the default HTTP status message for a given status code.\n *\n * @param statusCode - The HTTP status code\n * @returns The standard HTTP status message or 'Unknown Error' if not found\n * @private\n */\n private getDefaultStatusMessage(statusCode: number): string {\n const statusMessages: Record<number, string> = {\n 400: 'Bad Request',\n 401: 'Unauthorized',\n 403: 'Forbidden',\n 404: 'Not Found',\n 405: 'Method Not Allowed',\n 406: 'Not Acceptable',\n 408: 'Request Timeout',\n 409: 'Conflict',\n 410: 'Gone',\n 422: 'Unprocessable Entity',\n 429: 'Too Many Requests',\n 500: 'Internal Server Error',\n 501: 'Not Implemented',\n 502: 'Bad Gateway',\n 503: 'Service Unavailable',\n 504: 'Gateway Timeout',\n };\n return statusMessages[statusCode] || 'Unknown Error';\n }\n\n /**\n * Serializes the error to a JSON-compatible object.\n * Useful for logging and debugging purposes.\n *\n * @returns Object representation of the error including stack trace\n */\n toJSON() {\n return {\n name: this.name,\n message: this.message,\n statusCode: this.statusCode,\n statusMessage: this.statusMessage,\n code: this.code,\n details: this.details,\n stack: this.stack,\n };\n }\n}\n\n// Client Error Classes (4xx)\n\n/**\n * Represents a 400 Bad Request error.\n * Used when the client sends a malformed or invalid request.\n *\n * @extends HttpError\n *\n * @example\n * ```typescript\n * throw new BadRequestError('Invalid JSON', { line: 5, column: 12 });\n * ```\n */\nexport class BadRequestError extends HttpError {\n constructor(message?: string, details?: any) {\n super(400, message, { details });\n }\n}\n\n/**\n * Represents a 401 Unauthorized error.\n * Used when authentication is required but not provided or invalid.\n *\n * @extends HttpError\n *\n * @example\n * ```typescript\n * throw new UnauthorizedError('Invalid token');\n * ```\n */\nexport class UnauthorizedError extends HttpError {\n constructor(message?: string, details?: any) {\n super(401, message, { details });\n }\n}\n\n/**\n * Represents a 403 Forbidden error.\n * Used when the client is authenticated but lacks permission for the resource.\n *\n * @extends HttpError\n *\n * @example\n * ```typescript\n * throw new ForbiddenError('Insufficient permissions', { required: 'admin' });\n * ```\n */\nexport class ForbiddenError extends HttpError {\n constructor(message?: string, details?: any) {\n super(403, message, { details });\n }\n}\n\n/**\n * Represents a 404 Not Found error.\n * Used when the requested resource doesn't exist.\n *\n * @extends HttpError\n *\n * @example\n * ```typescript\n * throw new NotFoundError('User not found', { userId: '123' });\n * ```\n */\nexport class NotFoundError extends HttpError {\n constructor(message?: string, details?: any) {\n super(404, message, { details });\n }\n}\n\n/**\n * Represents a 405 Method Not Allowed error.\n * Used when the HTTP method is not supported for the requested resource.\n *\n * @extends HttpError\n *\n * @example\n * ```typescript\n * throw new MethodNotAllowedError('DELETE not supported', ['GET', 'POST', 'PUT']);\n * ```\n */\nexport class MethodNotAllowedError extends HttpError {\n /**\n * @param message - Optional error message\n * @param allowedMethods - Array of allowed HTTP methods for this resource\n */\n constructor(message?: string, allowedMethods?: string[]) {\n super(405, message, {\n details: allowedMethods ? { allowedMethods } : undefined,\n });\n }\n}\n\n/**\n * Represents a 409 Conflict error.\n * Used when the request conflicts with the current state of the resource.\n *\n * @extends HttpError\n *\n * @example\n * ```typescript\n * throw new ConflictError('Email already exists', { email: 'user@example.com' });\n * ```\n */\nexport class ConflictError extends HttpError {\n constructor(message?: string, details?: any) {\n super(409, message, { details });\n }\n}\n\n/**\n * Represents a 422 Unprocessable Entity error.\n * Used when the request is well-formed but contains semantic errors.\n *\n * @extends HttpError\n *\n * @example\n * ```typescript\n * throw new UnprocessableEntityError('Validation failed', {\n * email: 'Invalid format',\n * age: 'Must be 18 or older'\n * });\n * ```\n */\nexport class UnprocessableEntityError extends HttpError {\n /**\n * @param message - Optional error message\n * @param validationErrors - Object containing field-specific validation errors\n */\n constructor(message?: string, validationErrors?: any) {\n super(422, message, {\n details: validationErrors ? { validationErrors } : undefined,\n });\n }\n}\n\n/**\n * Represents a 429 Too Many Requests error.\n * Used when the client has exceeded rate limits.\n *\n * @extends HttpError\n *\n * @example\n * ```typescript\n * throw new TooManyRequestsError('Rate limit exceeded', 60); // retry after 60 seconds\n * ```\n */\nexport class TooManyRequestsError extends HttpError {\n /**\n * @param message - Optional error message\n * @param retryAfter - Number of seconds the client should wait before retrying\n */\n constructor(message?: string, retryAfter?: number) {\n super(429, message, {\n details: retryAfter ? { retryAfter } : undefined,\n });\n }\n}\n\n// Server Error Classes (5xx)\n\n/**\n * Represents a 500 Internal Server Error.\n * Used for unexpected server-side errors.\n *\n * @extends HttpError\n *\n * @example\n * ```typescript\n * throw new InternalServerError('Database connection failed');\n * ```\n */\nexport class InternalServerError extends HttpError {\n constructor(message?: string, details?: any) {\n super(500, message, { details });\n }\n}\n\n/**\n * Represents a 501 Not Implemented error.\n * Used when the server doesn't support the requested functionality.\n *\n * @extends HttpError\n *\n * @example\n * ```typescript\n * throw new NotImplementedError('WebSocket support not implemented');\n * ```\n */\nexport class NotImplementedError extends HttpError {\n constructor(message?: string, details?: any) {\n super(501, message, { details });\n }\n}\n\n/**\n * Represents a 502 Bad Gateway error.\n * Used when the server receives an invalid response from an upstream server.\n *\n * @extends HttpError\n *\n * @example\n * ```typescript\n * throw new BadGatewayError('Upstream server error');\n * ```\n */\nexport class BadGatewayError extends HttpError {\n constructor(message?: string, details?: any) {\n super(502, message, { details });\n }\n}\n\n/**\n * Represents a 503 Service Unavailable error.\n * Used when the server is temporarily unable to handle requests.\n *\n * @extends HttpError\n *\n * @example\n * ```typescript\n * throw new ServiceUnavailableError('Maintenance in progress', 300); // retry after 5 minutes\n * ```\n */\nexport class ServiceUnavailableError extends HttpError {\n /**\n * @param message - Optional error message\n * @param retryAfter - Number of seconds the client should wait before retrying\n */\n constructor(message?: string, retryAfter?: number) {\n super(503, message, {\n details: retryAfter ? { retryAfter } : undefined,\n });\n }\n}\n\n/**\n * Represents a 504 Gateway Timeout error.\n * Used when the server doesn't receive a timely response from an upstream server.\n *\n * @extends HttpError\n *\n * @example\n * ```typescript\n * throw new GatewayTimeoutError('Upstream server timeout');\n * ```\n */\nexport class GatewayTimeoutError extends HttpError {\n constructor(message?: string, details?: any) {\n super(504, message, { details });\n }\n}\n\n// Type definitions for different error factory signatures\n\n/** Factory function for standard HTTP errors with optional details */\ntype StandardErrorFactory = (message?: string, details?: any) => HttpError;\n/** Factory function for Method Not Allowed errors with allowed methods */\ntype MethodNotAllowedFactory = (\n message?: string,\n allowedMethods?: string[],\n) => MethodNotAllowedError;\n/** Factory function for errors that include retry-after information */\ntype RetryAfterFactory = (message?: string, retryAfter?: number) => HttpError;\n/** Factory function for validation errors with field-specific errors */\ntype ValidationErrorFactory = (\n message?: string,\n validationErrors?: any,\n) => UnprocessableEntityError;\n\n/** Discriminated union for all factory types */\ntype ErrorFactory =\n | { type: 'standard'; factory: StandardErrorFactory }\n | { type: 'methodNotAllowed'; factory: MethodNotAllowedFactory }\n | { type: 'retryAfter'; factory: RetryAfterFactory }\n | { type: 'validation'; factory: ValidationErrorFactory };\n\n/** Type-safe error registry mapping status codes to their factory functions */\nconst errorRegistry = {\n 400: {\n type: 'standard',\n factory: (m: string, d: any) => new BadRequestError(m, d),\n },\n 401: {\n type: 'standard',\n factory: (m: string, d: any) => new UnauthorizedError(m, d),\n },\n 403: {\n type: 'standard',\n factory: (m: string, d: any) => new ForbiddenError(m, d),\n },\n 404: {\n type: 'standard',\n factory: (m: string, d: any) => new NotFoundError(m, d),\n },\n 405: {\n type: 'methodNotAllowed',\n factory: (m: string, am: string[]) => new MethodNotAllowedError(m, am),\n },\n 409: {\n type: 'standard',\n factory: (m: string, d: any) => new ConflictError(m, d),\n },\n 422: {\n type: 'validation',\n factory: (m: string, ve: any) => new UnprocessableEntityError(m, ve),\n },\n 429: {\n type: 'retryAfter',\n factory: (m: string, ra: number) => new TooManyRequestsError(m, ra),\n },\n 500: {\n type: 'standard',\n factory: (m: string, d: any) => new InternalServerError(m, d),\n },\n 501: {\n type: 'standard',\n factory: (m: string, d: any) => new NotImplementedError(m, d),\n },\n 502: {\n type: 'standard',\n factory: (m: string, d: any) => new BadGatewayError(m, d),\n },\n 503: {\n type: 'retryAfter',\n factory: (m: string, ra: number) => new ServiceUnavailableError(m, ra),\n },\n 504: {\n type: 'standard',\n factory: (m: string, d: any) => new GatewayTimeoutError(m, d),\n },\n} as const;\n\n/** Valid status codes that have registered error factories */\ntype ValidStatusCode = keyof typeof errorRegistry;\n\n/** Type-safe options based on status code, ensuring correct parameters for each error type */\ntype ErrorOptions<T extends number> = T extends 405\n ? { allowedMethods?: string[]; code?: string; cause?: Error }\n : T extends 422\n ? { validationErrors?: any; code?: string; cause?: Error }\n : T extends 429 | 503\n ? { retryAfter?: number; code?: string; cause?: Error }\n : { details?: any; code?: string; cause?: Error };\n\n/** Handler functions for each factory type */\nconst factoryHandlers: Record<\n ErrorFactory['type'],\n (entry: any, message?: string, options?: any) => HttpError\n> = {\n standard: (entry, message, options) =>\n entry.factory(message, options?.details),\n methodNotAllowed: (entry, message, options) =>\n entry.factory(message, options?.allowedMethods),\n retryAfter: (entry, message, options) =>\n entry.factory(message, options?.retryAfter),\n validation: (entry, message, options) =>\n entry.factory(message, options?.validationErrors),\n};\n\n/**\n * Creates an HTTP error with type-safe options based on the status code.\n * Provides IntelliSense support for status-code-specific options.\n *\n * @overload For known status codes with specific options\n * @param statusCode - A valid HTTP status code from the registry\n * @param message - Optional error message\n * @param options - Status-code-specific options\n * @returns The appropriate HttpError subclass\n *\n * @example\n * ```typescript\n * // TypeScript knows allowedMethods is valid for 405\n * createHttpError(405, 'Method not allowed', { allowedMethods: ['GET', 'POST'] });\n *\n * // TypeScript knows retryAfter is valid for 429\n * createHttpError(429, 'Rate limited', { retryAfter: 60 });\n * ```\n */\nexport function createHttpError<T extends ValidStatusCode>(\n statusCode: T,\n message?: string,\n options?: ErrorOptions<T>,\n): HttpError;\nexport function createHttpError(\n statusCode: number,\n message?: string,\n options?: HttpErrorOptions,\n): HttpError;\nexport function createHttpError(\n statusCode: number,\n message?: string,\n options?: any,\n): HttpError {\n const entry = errorRegistry[statusCode as ValidStatusCode];\n\n if (entry) {\n const handler = factoryHandlers[entry.type];\n return handler(entry, message, options);\n }\n\n // Fallback to generic HttpError for unknown status codes\n return new HttpError(statusCode, message, options);\n}\n\n/**\n * Type-safe error creation utilities with descriptive method names.\n * Provides a fluent API for creating specific HTTP errors.\n *\n * @example\n * ```typescript\n * createError.notFound('User not found');\n * createError.badRequest('Invalid input', { field: 'email' });\n * createError.methodNotAllowed('DELETE not supported', ['GET', 'POST']);\n * ```\n */\nexport const createError = {\n badRequest: (message?: string, details?: any) =>\n new BadRequestError(message, details),\n\n unauthorized: (message?: string, details?: any) =>\n new UnauthorizedError(message, details),\n\n forbidden: (message?: string, details?: any) =>\n new ForbiddenError(message, details),\n\n notFound: (message?: string, details?: any) =>\n new NotFoundError(message, details),\n\n methodNotAllowed: (message?: string, allowedMethods?: string[]) =>\n new MethodNotAllowedError(message, allowedMethods),\n\n conflict: (message?: string, details?: any) =>\n new ConflictError(message, details),\n\n unprocessableEntity: (message?: string, validationErrors?: any) =>\n new UnprocessableEntityError(message, validationErrors),\n\n tooManyRequests: (message?: string, retryAfter?: number) =>\n new TooManyRequestsError(message, retryAfter),\n\n internalServerError: (message?: string, details?: any) =>\n new InternalServerError(message, details),\n\n notImplemented: (message?: string, details?: any) =>\n new NotImplementedError(message, details),\n\n badGateway: (message?: string, details?: any) =>\n new BadGatewayError(message, details),\n\n serviceUnavailable: (message?: string, retryAfter?: number) =>\n new ServiceUnavailableError(message, retryAfter),\n\n gatewayTimeout: (message?: string, details?: any) =>\n new GatewayTimeoutError(message, details),\n} as const;\n\n// Type guards\n\n/**\n * Type guard to check if an error is an HttpError.\n * Works with both instanceof checks and duck typing.\n *\n * @param error - The error to check\n * @returns True if the error is an HttpError\n *\n * @example\n * ```typescript\n * try {\n * // some code\n * } catch (error) {\n * if (isHttpError(error)) {\n * console.log(`HTTP ${error.statusCode}: ${error.message}`);\n * }\n * }\n * ```\n */\nexport function isHttpError(error: unknown): error is HttpError {\n return (\n error instanceof HttpError ||\n (error !== null &&\n typeof error === 'object' &&\n 'isHttpError' in error &&\n error.isHttpError === true)\n );\n}\n\n/**\n * Type guard to check if an error is a client error (4xx status code).\n *\n * @param error - The error to check\n * @returns True if the error is an HttpError with a 4xx status code\n *\n * @example\n * ```typescript\n * if (isClientError(error)) {\n * // Log client error metrics\n * }\n * ```\n */\nexport function isClientError(error: unknown): error is HttpError {\n return (\n isHttpError(error) && error.statusCode >= 400 && error.statusCode < 500\n );\n}\n\n/**\n * Type guard to check if an error is a server error (5xx status code).\n *\n * @param error - The error to check\n * @returns True if the error is an HttpError with a 5xx status code\n *\n * @example\n * ```typescript\n * if (isServerError(error)) {\n * // Trigger alerts for server errors\n * }\n * ```\n */\nexport function isServerError(error: unknown): error is HttpError {\n return (\n isHttpError(error) && error.statusCode >= 500 && error.statusCode < 600\n );\n}\n\n// Utility functions\n\n/**\n * Wraps an unknown error into an HttpError.\n * If the error is already an HttpError, returns it unchanged.\n *\n * @param error - The error to wrap\n * @param statusCode - The HTTP status code to use (defaults to 500)\n * @param message - Optional message to override the original error message\n * @returns An HttpError instance\n *\n * @example\n * ```typescript\n * try {\n * await someOperation();\n * } catch (error) {\n * throw wrapError(error, 503, 'Service temporarily unavailable');\n * }\n * ```\n */\nexport function wrapError(\n error: unknown,\n statusCode = 500,\n message?: string,\n): HttpError {\n if (isHttpError(error)) {\n return error;\n }\n\n if (error instanceof HttpError) {\n return error;\n }\n\n return new HttpError(statusCode, message || 'An unknown error occurred', {\n details: { originalError: error },\n });\n}\n\n// Types for better TypeScript support\n\n/**\n * Options for creating an HttpError.\n */\nexport interface HttpErrorOptions {\n statusMessage?: string;\n details?: any;\n code?: string;\n cause?: Error;\n}\n\n/**\n * Constructor type for HttpError classes.\n * Useful for factory patterns and dependency injection.\n */\nexport type HttpErrorConstructor = new (\n message?: string,\n options?: HttpErrorOptions,\n) => HttpError;\n\n/**\n * HTTP status code enum for type-safe status code usage.\n * Includes common 2xx, 3xx, 4xx, and 5xx status codes.\n */\nexport enum HttpStatusCode {\n // 2xx Success\n OK = 200,\n CREATED = 201,\n ACCEPTED = 202,\n NO_CONTENT = 204,\n\n // 3xx Redirection\n MOVED_PERMANENTLY = 301,\n FOUND = 302,\n NOT_MODIFIED = 304,\n\n // 4xx Client Error\n BAD_REQUEST = 400,\n UNAUTHORIZED = 401,\n FORBIDDEN = 403,\n NOT_FOUND = 404,\n METHOD_NOT_ALLOWED = 405,\n NOT_ACCEPTABLE = 406,\n REQUEST_TIMEOUT = 408,\n CONFLICT = 409,\n GONE = 410,\n UNPROCESSABLE_ENTITY = 422,\n TOO_MANY_REQUESTS = 429,\n\n // 5xx Server Error\n INTERNAL_SERVER_ERROR = 500,\n NOT_IMPLEMENTED = 501,\n BAD_GATEWAY = 502,\n SERVICE_UNAVAILABLE = 503,\n GATEWAY_TIMEOUT = 504,\n}\n\n/**\n * Namespace containing all HTTP error classes.\n * Useful for importing all error types at once.\n *\n * @example\n * ```typescript\n * import { HttpErrors } from '@geekmidas/errors';\n * throw new HttpErrors.NotFoundError('Resource not found');\n * ```\n */\nexport const HttpErrors = {\n HttpError,\n BadRequestError,\n UnauthorizedError,\n ForbiddenError,\n NotFoundError,\n MethodNotAllowedError,\n ConflictError,\n UnprocessableEntityError,\n TooManyRequestsError,\n InternalServerError,\n NotImplementedError,\n BadGatewayError,\n ServiceUnavailableError,\n GatewayTimeoutError,\n};\n\n// Usage examples:\n/*\n// Basic usage\nthrow new NotFoundError('User not found');\nthrow new BadRequestError('Invalid email format', { field: 'email' });\n\n// With validation errors\nthrow new UnprocessableEntityError('Validation failed', {\n email: 'Invalid email format',\n password: 'Password must be at least 8 characters',\n});\n\n// Type-safe factory function with IntelliSense support\nthrow createHttpError(405, 'Method not allowed', { \n allowedMethods: ['GET', 'POST'] // TypeScript knows this is the correct option!\n});\n\nthrow createHttpError(429, 'Too many requests', { \n retryAfter: 60 // TypeScript knows this needs retryAfter, not details!\n});\n\nthrow createHttpError(422, 'Validation failed', {\n validationErrors: { // TypeScript knows this is for validation errors\n email: 'Invalid format',\n age: 'Must be 18+'\n }\n});\n\n// Using the type-safe createError object\nthrow createError.methodNotAllowed('DELETE not supported', ['GET', 'POST']);\nthrow createError.tooManyRequests('Rate limit exceeded', 60);\nthrow createError.unprocessableEntity('Invalid input', {\n field: 'email',\n message: 'Invalid format'\n});\n\n// TypeScript will show errors for incorrect usage:\n// throw createHttpError(404, 'Not found', { retryAfter: 60 }); // ❌ Type error!\n// throw createError.notFound('User not found', 60); // ❌ Type error!\n\n// Wrapping unknown errors\ntry {\n await someAsyncOperation();\n} catch (error) {\n throw wrapError(error, 500, 'Failed to process request');\n}\n\n// In Express middleware\napp.use(expressErrorHandler);\n\n// Type checking\nif (isClientError(error)) {\n console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