@geekmidas/errors 10.0.0-alpha.12 → 10.0.0-alpha.121

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 CHANGED
@@ -1,4 +1,4 @@
1
-
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
2
  //#region src/index.ts
3
3
  /**
4
4
  * Base HTTP Error class that extends the native Error.
@@ -25,6 +25,13 @@ var HttpError = class extends Error {
25
25
  /** Application-specific error code for client-side handling */
26
26
  code;
27
27
  /**
28
+ * Headers the response that reports this error carries — a 429's
29
+ * `Retry-After`, a 401's `WWW-Authenticate`. Every endpoint adaptor sets
30
+ * them on the error response, so the error says everything the client is
31
+ * told.
32
+ */
33
+ headers;
34
+ /**
28
35
  * Creates a new HttpError instance.
29
36
  *
30
37
  * @param statusCode - The HTTP status code
@@ -33,6 +40,7 @@ var HttpError = class extends Error {
33
40
  * @param options.statusMessage - Override the default status message
34
41
  * @param options.details - Additional error details or context
35
42
  * @param options.code - Application-specific error code
43
+ * @param options.headers - Headers the error response carries
36
44
  * @param options.cause - The underlying error that caused this error (ES2022)
37
45
  */
38
46
  constructor(statusCode, message, options) {
@@ -42,6 +50,7 @@ var HttpError = class extends Error {
42
50
  this.statusMessage = options?.statusMessage || this.getDefaultStatusMessage(statusCode);
43
51
  this.details = options?.details;
44
52
  this.code = options?.code;
53
+ if (options?.headers) this.headers = options.headers;
45
54
  if (options?.cause) this.cause = options.cause;
46
55
  Error.captureStackTrace(this, this.constructor);
47
56
  }
@@ -66,7 +75,7 @@ var HttpError = class extends Error {
66
75
  * @private
67
76
  */
68
77
  getDefaultStatusMessage(statusCode) {
69
- const statusMessages = {
78
+ return {
70
79
  400: "Bad Request",
71
80
  401: "Unauthorized",
72
81
  403: "Forbidden",
@@ -83,8 +92,7 @@ var HttpError = class extends Error {
83
92
  502: "Bad Gateway",
84
93
  503: "Service Unavailable",
85
94
  504: "Gateway Timeout"
86
- };
87
- return statusMessages[statusCode] || "Unknown Error";
95
+ }[statusCode] || "Unknown Error";
88
96
  }
89
97
  /**
90
98
  * Serializes the error to a JSON-compatible object.
@@ -239,12 +247,25 @@ var UnprocessableEntityError = class extends HttpError {
239
247
  * ```
240
248
  */
241
249
  var TooManyRequestsError = class extends HttpError {
250
+ /** Seconds the client should wait before retrying, where known. */
251
+ retryAfter;
242
252
  /**
243
253
  * @param message - Optional error message
244
- * @param retryAfter - Number of seconds the client should wait before retrying
254
+ * @param retryAfter - Number of seconds the client should wait before
255
+ * retrying, sent as the `Retry-After` header
256
+ * @param options.headers - Further headers the response carries, such as
257
+ * a rate limiter's `X-RateLimit-*`
245
258
  */
246
- constructor(message, retryAfter) {
247
- super(429, message, { details: retryAfter ? { retryAfter } : void 0 });
259
+ constructor(message, retryAfter, options) {
260
+ const headers = {
261
+ ...options?.headers,
262
+ ...retryAfter !== void 0 ? { "Retry-After": String(retryAfter) } : {}
263
+ };
264
+ super(429, message, {
265
+ details: retryAfter !== void 0 ? { retryAfter } : void 0,
266
+ ...Object.keys(headers).length > 0 ? { headers } : {}
267
+ });
268
+ if (retryAfter !== void 0) this.retryAfter = retryAfter;
248
269
  }
249
270
  };
250
271
  /**
@@ -482,7 +503,13 @@ function isServerError(error) {
482
503
  }
483
504
  /**
484
505
  * Wraps an unknown error into an HttpError.
485
- * If the error is already an HttpError, returns it unchanged.
506
+ *
507
+ * One rule: an error that is an HttpError ({@link isHttpError}) passes
508
+ * through unchanged, its status and headers with it; anything else — however
509
+ * it is shaped, a `statusCode` field included — becomes `statusCode` (500 by
510
+ * default). An error that should answer with its own status extends
511
+ * HttpError, so the decision is made where the error is defined rather than
512
+ * guessed from its fields here.
486
513
  *
487
514
  * @param error - The error to wrap
488
515
  * @param statusCode - The HTTP status code to use (defaults to 500)
@@ -500,38 +527,37 @@ function isServerError(error) {
500
527
  */
501
528
  function wrapError(error, statusCode = 500, message) {
502
529
  if (isHttpError(error)) return error;
503
- if (error instanceof HttpError) return error;
504
530
  return new HttpError(statusCode, message || "An unknown error occurred", { details: { originalError: error } });
505
531
  }
506
532
  /**
507
533
  * HTTP status code enum for type-safe status code usage.
508
534
  * Includes common 2xx, 3xx, 4xx, and 5xx status codes.
509
535
  */
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;
536
+ let HttpStatusCode = /* @__PURE__ */ function(HttpStatusCode) {
537
+ HttpStatusCode[HttpStatusCode["OK"] = 200] = "OK";
538
+ HttpStatusCode[HttpStatusCode["CREATED"] = 201] = "CREATED";
539
+ HttpStatusCode[HttpStatusCode["ACCEPTED"] = 202] = "ACCEPTED";
540
+ HttpStatusCode[HttpStatusCode["NO_CONTENT"] = 204] = "NO_CONTENT";
541
+ HttpStatusCode[HttpStatusCode["MOVED_PERMANENTLY"] = 301] = "MOVED_PERMANENTLY";
542
+ HttpStatusCode[HttpStatusCode["FOUND"] = 302] = "FOUND";
543
+ HttpStatusCode[HttpStatusCode["NOT_MODIFIED"] = 304] = "NOT_MODIFIED";
544
+ HttpStatusCode[HttpStatusCode["BAD_REQUEST"] = 400] = "BAD_REQUEST";
545
+ HttpStatusCode[HttpStatusCode["UNAUTHORIZED"] = 401] = "UNAUTHORIZED";
546
+ HttpStatusCode[HttpStatusCode["FORBIDDEN"] = 403] = "FORBIDDEN";
547
+ HttpStatusCode[HttpStatusCode["NOT_FOUND"] = 404] = "NOT_FOUND";
548
+ HttpStatusCode[HttpStatusCode["METHOD_NOT_ALLOWED"] = 405] = "METHOD_NOT_ALLOWED";
549
+ HttpStatusCode[HttpStatusCode["NOT_ACCEPTABLE"] = 406] = "NOT_ACCEPTABLE";
550
+ HttpStatusCode[HttpStatusCode["REQUEST_TIMEOUT"] = 408] = "REQUEST_TIMEOUT";
551
+ HttpStatusCode[HttpStatusCode["CONFLICT"] = 409] = "CONFLICT";
552
+ HttpStatusCode[HttpStatusCode["GONE"] = 410] = "GONE";
553
+ HttpStatusCode[HttpStatusCode["UNPROCESSABLE_ENTITY"] = 422] = "UNPROCESSABLE_ENTITY";
554
+ HttpStatusCode[HttpStatusCode["TOO_MANY_REQUESTS"] = 429] = "TOO_MANY_REQUESTS";
555
+ HttpStatusCode[HttpStatusCode["INTERNAL_SERVER_ERROR"] = 500] = "INTERNAL_SERVER_ERROR";
556
+ HttpStatusCode[HttpStatusCode["NOT_IMPLEMENTED"] = 501] = "NOT_IMPLEMENTED";
557
+ HttpStatusCode[HttpStatusCode["BAD_GATEWAY"] = 502] = "BAD_GATEWAY";
558
+ HttpStatusCode[HttpStatusCode["SERVICE_UNAVAILABLE"] = 503] = "SERVICE_UNAVAILABLE";
559
+ HttpStatusCode[HttpStatusCode["GATEWAY_TIMEOUT"] = 504] = "GATEWAY_TIMEOUT";
560
+ return HttpStatusCode;
535
561
  }({});
536
562
  /**
537
563
  * Namespace containing all HTTP error classes.
@@ -559,7 +585,6 @@ const HttpErrors = {
559
585
  ServiceUnavailableError,
560
586
  GatewayTimeoutError
561
587
  };
562
-
563
588
  //#endregion
564
589
  exports.BadGatewayError = BadGatewayError;
565
590
  exports.BadRequestError = BadRequestError;
@@ -583,4 +608,5 @@ exports.isClientError = isClientError;
583
608
  exports.isHttpError = isHttpError;
584
609
  exports.isServerError = isServerError;
585
610
  exports.wrapError = wrapError;
611
+
586
612
  //# sourceMappingURL=index.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.cjs","names":["statusCode: number","message?: string","options?: {\n\t\t\tstatusMessage?: string;\n\t\t\tdetails?: any;\n\t\t\tcode?: string;\n\t\t\tcause?: Error;\n\t\t}","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\tErrorFactory['type'],\n\t(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\t/** The HTTP status code (e.g., 400, 404, 500) */\n\tpublic readonly statusCode: number;\n\t/** The standard HTTP status message (e.g., 'Bad Request', 'Not Found') */\n\tpublic readonly statusMessage: string;\n\t/** Type discriminator for runtime type checking */\n\tpublic readonly isHttpError = true;\n\t/** Additional error details for debugging or client information */\n\tpublic readonly details?: any;\n\t/** Application-specific error code for client-side handling */\n\tpublic readonly code?: string;\n\n\t/**\n\t * Creates a new HttpError instance.\n\t *\n\t * @param statusCode - The HTTP status code\n\t * @param message - Optional error message for the client\n\t * @param options - Optional configuration object\n\t * @param options.statusMessage - Override the default status message\n\t * @param options.details - Additional error details or context\n\t * @param options.code - Application-specific error code\n\t * @param options.cause - The underlying error that caused this error (ES2022)\n\t */\n\tconstructor(\n\t\tstatusCode: number,\n\t\tmessage?: string,\n\t\toptions?: {\n\t\t\tstatusMessage?: string;\n\t\t\tdetails?: any;\n\t\t\tcode?: string;\n\t\t\tcause?: Error;\n\t\t},\n\t) {\n\t\tsuper(message || options?.statusMessage || 'HTTP Error');\n\t\tthis.name = this.constructor.name;\n\t\tthis.statusCode = statusCode;\n\t\tthis.statusMessage =\n\t\t\toptions?.statusMessage || this.getDefaultStatusMessage(statusCode);\n\t\tthis.details = options?.details;\n\t\tthis.code = options?.code;\n\n\t\t// Set cause if provided (ES2022 feature)\n\t\tif (options?.cause) {\n\t\t\tthis.cause = options.cause;\n\t\t}\n\t\t// Maintains proper stack trace for where our error was thrown\n\t\tError.captureStackTrace(this, this.constructor);\n\t}\n\n\t/**\n\t * Gets the error response body as a JSON string.\n\t * Used for sending the error response to clients.\n\t *\n\t * @returns JSON string containing message, code, and error details\n\t */\n\tget body() {\n\t\treturn JSON.stringify({\n\t\t\tmessage: this.message,\n\t\t\tcode: this.code,\n\t\t\terror: this.details,\n\t\t});\n\t}\n\n\t/**\n\t * Gets the default HTTP status message for a given status code.\n\t *\n\t * @param statusCode - The HTTP status code\n\t * @returns The standard HTTP status message or 'Unknown Error' if not found\n\t * @private\n\t */\n\tprivate getDefaultStatusMessage(statusCode: number): string {\n\t\tconst statusMessages: Record<number, string> = {\n\t\t\t400: 'Bad Request',\n\t\t\t401: 'Unauthorized',\n\t\t\t403: 'Forbidden',\n\t\t\t404: 'Not Found',\n\t\t\t405: 'Method Not Allowed',\n\t\t\t406: 'Not Acceptable',\n\t\t\t408: 'Request Timeout',\n\t\t\t409: 'Conflict',\n\t\t\t410: 'Gone',\n\t\t\t422: 'Unprocessable Entity',\n\t\t\t429: 'Too Many Requests',\n\t\t\t500: 'Internal Server Error',\n\t\t\t501: 'Not Implemented',\n\t\t\t502: 'Bad Gateway',\n\t\t\t503: 'Service Unavailable',\n\t\t\t504: 'Gateway Timeout',\n\t\t};\n\t\treturn statusMessages[statusCode] || 'Unknown Error';\n\t}\n\n\t/**\n\t * Serializes the error to a JSON-compatible object.\n\t * Useful for logging and debugging purposes.\n\t *\n\t * @returns Object representation of the error including stack trace\n\t */\n\ttoJSON() {\n\t\treturn {\n\t\t\tname: this.name,\n\t\t\tmessage: this.message,\n\t\t\tstatusCode: this.statusCode,\n\t\t\tstatusMessage: this.statusMessage,\n\t\t\tcode: this.code,\n\t\t\tdetails: this.details,\n\t\t\tstack: this.stack,\n\t\t};\n\t}\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\tconstructor(message?: string, details?: any) {\n\t\tsuper(400, message, { details });\n\t}\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\tconstructor(message?: string, details?: any) {\n\t\tsuper(401, message, { details });\n\t}\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\tconstructor(message?: string, details?: any) {\n\t\tsuper(403, message, { details });\n\t}\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\tconstructor(message?: string, details?: any) {\n\t\tsuper(404, message, { details });\n\t}\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\t/**\n\t * @param message - Optional error message\n\t * @param allowedMethods - Array of allowed HTTP methods for this resource\n\t */\n\tconstructor(message?: string, allowedMethods?: string[]) {\n\t\tsuper(405, message, {\n\t\t\tdetails: allowedMethods ? { allowedMethods } : undefined,\n\t\t});\n\t}\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\tconstructor(message?: string, details?: any) {\n\t\tsuper(409, message, { details });\n\t}\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\t/**\n\t * @param message - Optional error message\n\t * @param validationErrors - Object containing field-specific validation errors\n\t */\n\tconstructor(message?: string, validationErrors?: any) {\n\t\tsuper(422, message, {\n\t\t\tdetails: validationErrors ? { validationErrors } : undefined,\n\t\t});\n\t}\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\t/**\n\t * @param message - Optional error message\n\t * @param retryAfter - Number of seconds the client should wait before retrying\n\t */\n\tconstructor(message?: string, retryAfter?: number) {\n\t\tsuper(429, message, {\n\t\t\tdetails: retryAfter ? { retryAfter } : undefined,\n\t\t});\n\t}\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\tconstructor(message?: string, details?: any) {\n\t\tsuper(500, message, { details });\n\t}\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\tconstructor(message?: string, details?: any) {\n\t\tsuper(501, message, { details });\n\t}\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\tconstructor(message?: string, details?: any) {\n\t\tsuper(502, message, { details });\n\t}\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\t/**\n\t * @param message - Optional error message\n\t * @param retryAfter - Number of seconds the client should wait before retrying\n\t */\n\tconstructor(message?: string, retryAfter?: number) {\n\t\tsuper(503, message, {\n\t\t\tdetails: retryAfter ? { retryAfter } : undefined,\n\t\t});\n\t}\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\tconstructor(message?: string, details?: any) {\n\t\tsuper(504, message, { details });\n\t}\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\tmessage?: string,\n\tallowedMethods?: 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\tmessage?: string,\n\tvalidationErrors?: any,\n) => UnprocessableEntityError;\n\n/** Discriminated union for all factory types */\ntype ErrorFactory =\n\t| { type: 'standard'; factory: StandardErrorFactory }\n\t| { type: 'methodNotAllowed'; factory: MethodNotAllowedFactory }\n\t| { type: 'retryAfter'; factory: RetryAfterFactory }\n\t| { type: 'validation'; factory: ValidationErrorFactory };\n\n/** Type-safe error registry mapping status codes to their factory functions */\nconst errorRegistry = {\n\t400: {\n\t\ttype: 'standard',\n\t\tfactory: (m: string, d: any) => new BadRequestError(m, d),\n\t},\n\t401: {\n\t\ttype: 'standard',\n\t\tfactory: (m: string, d: any) => new UnauthorizedError(m, d),\n\t},\n\t403: {\n\t\ttype: 'standard',\n\t\tfactory: (m: string, d: any) => new ForbiddenError(m, d),\n\t},\n\t404: {\n\t\ttype: 'standard',\n\t\tfactory: (m: string, d: any) => new NotFoundError(m, d),\n\t},\n\t405: {\n\t\ttype: 'methodNotAllowed',\n\t\tfactory: (m: string, am: string[]) => new MethodNotAllowedError(m, am),\n\t},\n\t409: {\n\t\ttype: 'standard',\n\t\tfactory: (m: string, d: any) => new ConflictError(m, d),\n\t},\n\t422: {\n\t\ttype: 'validation',\n\t\tfactory: (m: string, ve: any) => new UnprocessableEntityError(m, ve),\n\t},\n\t429: {\n\t\ttype: 'retryAfter',\n\t\tfactory: (m: string, ra: number) => new TooManyRequestsError(m, ra),\n\t},\n\t500: {\n\t\ttype: 'standard',\n\t\tfactory: (m: string, d: any) => new InternalServerError(m, d),\n\t},\n\t501: {\n\t\ttype: 'standard',\n\t\tfactory: (m: string, d: any) => new NotImplementedError(m, d),\n\t},\n\t502: {\n\t\ttype: 'standard',\n\t\tfactory: (m: string, d: any) => new BadGatewayError(m, d),\n\t},\n\t503: {\n\t\ttype: 'retryAfter',\n\t\tfactory: (m: string, ra: number) => new ServiceUnavailableError(m, ra),\n\t},\n\t504: {\n\t\ttype: 'standard',\n\t\tfactory: (m: string, d: any) => new GatewayTimeoutError(m, d),\n\t},\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\t? { allowedMethods?: string[]; code?: string; cause?: Error }\n\t: T extends 422\n\t\t? { validationErrors?: any; code?: string; cause?: Error }\n\t\t: T extends 429 | 503\n\t\t\t? { retryAfter?: number; code?: string; cause?: Error }\n\t\t\t: { details?: any; code?: string; cause?: Error };\n\n/** Handler functions for each factory type */\nconst factoryHandlers: Record<\n\tErrorFactory['type'],\n\t(entry: any, message?: string, options?: any) => HttpError\n> = {\n\tstandard: (entry, message, options) =>\n\t\tentry.factory(message, options?.details),\n\tmethodNotAllowed: (entry, message, options) =>\n\t\tentry.factory(message, options?.allowedMethods),\n\tretryAfter: (entry, message, options) =>\n\t\tentry.factory(message, options?.retryAfter),\n\tvalidation: (entry, message, options) =>\n\t\tentry.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\tstatusCode: T,\n\tmessage?: string,\n\toptions?: ErrorOptions<T>,\n): HttpError;\nexport function createHttpError(\n\tstatusCode: number,\n\tmessage?: string,\n\toptions?: HttpErrorOptions,\n): HttpError;\nexport function createHttpError(\n\tstatusCode: number,\n\tmessage?: string,\n\toptions?: any,\n): HttpError {\n\tconst entry = errorRegistry[statusCode as ValidStatusCode];\n\n\tif (entry) {\n\t\tconst handler = factoryHandlers[entry.type];\n\t\treturn handler(entry, message, options);\n\t}\n\n\t// Fallback to generic HttpError for unknown status codes\n\treturn 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\tbadRequest: (message?: string, details?: any) =>\n\t\tnew BadRequestError(message, details),\n\n\tunauthorized: (message?: string, details?: any) =>\n\t\tnew UnauthorizedError(message, details),\n\n\tforbidden: (message?: string, details?: any) =>\n\t\tnew ForbiddenError(message, details),\n\n\tnotFound: (message?: string, details?: any) =>\n\t\tnew NotFoundError(message, details),\n\n\tmethodNotAllowed: (message?: string, allowedMethods?: string[]) =>\n\t\tnew MethodNotAllowedError(message, allowedMethods),\n\n\tconflict: (message?: string, details?: any) =>\n\t\tnew ConflictError(message, details),\n\n\tunprocessableEntity: (message?: string, validationErrors?: any) =>\n\t\tnew UnprocessableEntityError(message, validationErrors),\n\n\ttooManyRequests: (message?: string, retryAfter?: number) =>\n\t\tnew TooManyRequestsError(message, retryAfter),\n\n\tinternalServerError: (message?: string, details?: any) =>\n\t\tnew InternalServerError(message, details),\n\n\tnotImplemented: (message?: string, details?: any) =>\n\t\tnew NotImplementedError(message, details),\n\n\tbadGateway: (message?: string, details?: any) =>\n\t\tnew BadGatewayError(message, details),\n\n\tserviceUnavailable: (message?: string, retryAfter?: number) =>\n\t\tnew ServiceUnavailableError(message, retryAfter),\n\n\tgatewayTimeout: (message?: string, details?: any) =>\n\t\tnew 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\treturn (\n\t\terror instanceof HttpError ||\n\t\t(error !== null &&\n\t\t\ttypeof error === 'object' &&\n\t\t\t'isHttpError' in error &&\n\t\t\terror.isHttpError === true)\n\t);\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\treturn (\n\t\tisHttpError(error) && error.statusCode >= 400 && error.statusCode < 500\n\t);\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\treturn (\n\t\tisHttpError(error) && error.statusCode >= 500 && error.statusCode < 600\n\t);\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\terror: unknown,\n\tstatusCode = 500,\n\tmessage?: string,\n): HttpError {\n\tif (isHttpError(error)) {\n\t\treturn error;\n\t}\n\n\tif (error instanceof HttpError) {\n\t\treturn error;\n\t}\n\n\treturn new HttpError(statusCode, message || 'An unknown error occurred', {\n\t\tdetails: { originalError: error },\n\t});\n}\n\n// Types for better TypeScript support\n\n/**\n * Options for creating an HttpError.\n */\nexport interface HttpErrorOptions {\n\tstatusMessage?: string;\n\tdetails?: any;\n\tcode?: string;\n\tcause?: Error;\n}\n\n/**\n * Constructor type for HttpError classes.\n * Useful for factory patterns and dependency injection.\n */\nexport type HttpErrorConstructor = new (\n\tmessage?: string,\n\toptions?: 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\t// 2xx Success\n\tOK = 200,\n\tCREATED = 201,\n\tACCEPTED = 202,\n\tNO_CONTENT = 204,\n\n\t// 3xx Redirection\n\tMOVED_PERMANENTLY = 301,\n\tFOUND = 302,\n\tNOT_MODIFIED = 304,\n\n\t// 4xx Client Error\n\tBAD_REQUEST = 400,\n\tUNAUTHORIZED = 401,\n\tFORBIDDEN = 403,\n\tNOT_FOUND = 404,\n\tMETHOD_NOT_ALLOWED = 405,\n\tNOT_ACCEPTABLE = 406,\n\tREQUEST_TIMEOUT = 408,\n\tCONFLICT = 409,\n\tGONE = 410,\n\tUNPROCESSABLE_ENTITY = 422,\n\tTOO_MANY_REQUESTS = 429,\n\n\t// 5xx Server Error\n\tINTERNAL_SERVER_ERROR = 500,\n\tNOT_IMPLEMENTED = 501,\n\tBAD_GATEWAY = 502,\n\tSERVICE_UNAVAILABLE = 503,\n\tGATEWAY_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\tHttpError,\n\tBadRequestError,\n\tUnauthorizedError,\n\tForbiddenError,\n\tNotFoundError,\n\tMethodNotAllowedError,\n\tConflictError,\n\tUnprocessableEntityError,\n\tTooManyRequestsError,\n\tInternalServerError,\n\tNotImplementedError,\n\tBadGatewayError,\n\tServiceUnavailableError,\n\tGatewayTimeoutError,\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.log('Client made a bad request');\n}\n*/\n"],"mappings":";;;;;;;;;;;;;;;AAeA,IAAa,YAAb,cAA+B,MAAM;;CAEpC,AAAgB;;CAEhB,AAAgB;;CAEhB,AAAgB,cAAc;;CAE9B,AAAgB;;CAEhB,AAAgB;;;;;;;;;;;;CAahB,YACCA,YACAC,SACAC,SAMC;AACD,QAAM,WAAW,SAAS,iBAAiB,aAAa;AACxD,OAAK,OAAO,KAAK,YAAY;AAC7B,OAAK,aAAa;AAClB,OAAK,gBACJ,SAAS,iBAAiB,KAAK,wBAAwB,WAAW;AACnE,OAAK,UAAU,SAAS;AACxB,OAAK,OAAO,SAAS;AAGrB,MAAI,SAAS,MACZ,MAAK,QAAQ,QAAQ;AAGtB,QAAM,kBAAkB,MAAM,KAAK,YAAY;CAC/C;;;;;;;CAQD,IAAI,OAAO;AACV,SAAO,KAAK,UAAU;GACrB,SAAS,KAAK;GACd,MAAM,KAAK;GACX,OAAO,KAAK;EACZ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;;;;;;;;;;;;;;;;AAsBD,SAAgB,UACfA,OACA,aAAa,KACbd,SACY;AACZ,KAAI,YAAY,MAAM,CACrB,QAAO;AAGR,KAAI,iBAAiB,UACpB,QAAO;AAGR,QAAO,IAAI,UAAU,YAAY,WAAW,6BAA6B,EACxE,SAAS,EAAE,eAAe,MAAO,EACjC;AACD;;;;;AA2BD,IAAY,4DAAL;AAEN;AACA;AACA;AACA;AAGA;AACA;AACA;AAGA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAGA;AACA;AACA;AACA;AACA;;AACA;;;;;;;;;;;AAYD,MAAa,aAAa;CACzB;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACA"}
1
+ {"version":3,"file":"index.cjs","names":[],"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\t/** The HTTP status code (e.g., 400, 404, 500) */\n\tpublic readonly statusCode: number;\n\t/** The standard HTTP status message (e.g., 'Bad Request', 'Not Found') */\n\tpublic readonly statusMessage: string;\n\t/** Type discriminator for runtime type checking */\n\tpublic readonly isHttpError = true;\n\t/** Additional error details for debugging or client information */\n\tpublic readonly details?: any;\n\t/** Application-specific error code for client-side handling */\n\tpublic readonly code?: string;\n\t/**\n\t * Headers the response that reports this error carries — a 429's\n\t * `Retry-After`, a 401's `WWW-Authenticate`. Every endpoint adaptor sets\n\t * them on the error response, so the error says everything the client is\n\t * told.\n\t */\n\tpublic readonly headers?: Readonly<Record<string, string>>;\n\n\t/**\n\t * Creates a new HttpError instance.\n\t *\n\t * @param statusCode - The HTTP status code\n\t * @param message - Optional error message for the client\n\t * @param options - Optional configuration object\n\t * @param options.statusMessage - Override the default status message\n\t * @param options.details - Additional error details or context\n\t * @param options.code - Application-specific error code\n\t * @param options.headers - Headers the error response carries\n\t * @param options.cause - The underlying error that caused this error (ES2022)\n\t */\n\tconstructor(\n\t\tstatusCode: number,\n\t\tmessage?: string,\n\t\toptions?: {\n\t\t\tstatusMessage?: string;\n\t\t\tdetails?: any;\n\t\t\tcode?: string;\n\t\t\theaders?: Readonly<Record<string, string>>;\n\t\t\tcause?: Error;\n\t\t},\n\t) {\n\t\tsuper(message || options?.statusMessage || 'HTTP Error');\n\t\tthis.name = this.constructor.name;\n\t\tthis.statusCode = statusCode;\n\t\tthis.statusMessage =\n\t\t\toptions?.statusMessage || this.getDefaultStatusMessage(statusCode);\n\t\tthis.details = options?.details;\n\t\tthis.code = options?.code;\n\t\tif (options?.headers) this.headers = options.headers;\n\n\t\t// Set cause if provided (ES2022 feature)\n\t\tif (options?.cause) {\n\t\t\tthis.cause = options.cause;\n\t\t}\n\t\t// Maintains proper stack trace for where our error was thrown\n\t\tError.captureStackTrace(this, this.constructor);\n\t}\n\n\t/**\n\t * Gets the error response body as a JSON string.\n\t * Used for sending the error response to clients.\n\t *\n\t * @returns JSON string containing message, code, and error details\n\t */\n\tget body() {\n\t\treturn JSON.stringify({\n\t\t\tmessage: this.message,\n\t\t\tcode: this.code,\n\t\t\terror: this.details,\n\t\t});\n\t}\n\n\t/**\n\t * Gets the default HTTP status message for a given status code.\n\t *\n\t * @param statusCode - The HTTP status code\n\t * @returns The standard HTTP status message or 'Unknown Error' if not found\n\t * @private\n\t */\n\tprivate getDefaultStatusMessage(statusCode: number): string {\n\t\tconst statusMessages: Record<number, string> = {\n\t\t\t400: 'Bad Request',\n\t\t\t401: 'Unauthorized',\n\t\t\t403: 'Forbidden',\n\t\t\t404: 'Not Found',\n\t\t\t405: 'Method Not Allowed',\n\t\t\t406: 'Not Acceptable',\n\t\t\t408: 'Request Timeout',\n\t\t\t409: 'Conflict',\n\t\t\t410: 'Gone',\n\t\t\t422: 'Unprocessable Entity',\n\t\t\t429: 'Too Many Requests',\n\t\t\t500: 'Internal Server Error',\n\t\t\t501: 'Not Implemented',\n\t\t\t502: 'Bad Gateway',\n\t\t\t503: 'Service Unavailable',\n\t\t\t504: 'Gateway Timeout',\n\t\t};\n\t\treturn statusMessages[statusCode] || 'Unknown Error';\n\t}\n\n\t/**\n\t * Serializes the error to a JSON-compatible object.\n\t * Useful for logging and debugging purposes.\n\t *\n\t * @returns Object representation of the error including stack trace\n\t */\n\ttoJSON() {\n\t\treturn {\n\t\t\tname: this.name,\n\t\t\tmessage: this.message,\n\t\t\tstatusCode: this.statusCode,\n\t\t\tstatusMessage: this.statusMessage,\n\t\t\tcode: this.code,\n\t\t\tdetails: this.details,\n\t\t\tstack: this.stack,\n\t\t};\n\t}\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\tconstructor(message?: string, details?: any) {\n\t\tsuper(400, message, { details });\n\t}\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\tconstructor(message?: string, details?: any) {\n\t\tsuper(401, message, { details });\n\t}\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\tconstructor(message?: string, details?: any) {\n\t\tsuper(403, message, { details });\n\t}\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\tconstructor(message?: string, details?: any) {\n\t\tsuper(404, message, { details });\n\t}\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\t/**\n\t * @param message - Optional error message\n\t * @param allowedMethods - Array of allowed HTTP methods for this resource\n\t */\n\tconstructor(message?: string, allowedMethods?: string[]) {\n\t\tsuper(405, message, {\n\t\t\tdetails: allowedMethods ? { allowedMethods } : undefined,\n\t\t});\n\t}\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\tconstructor(message?: string, details?: any) {\n\t\tsuper(409, message, { details });\n\t}\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\t/**\n\t * @param message - Optional error message\n\t * @param validationErrors - Object containing field-specific validation errors\n\t */\n\tconstructor(message?: string, validationErrors?: any) {\n\t\tsuper(422, message, {\n\t\t\tdetails: validationErrors ? { validationErrors } : undefined,\n\t\t});\n\t}\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\t/** Seconds the client should wait before retrying, where known. */\n\tpublic readonly retryAfter?: number;\n\n\t/**\n\t * @param message - Optional error message\n\t * @param retryAfter - Number of seconds the client should wait before\n\t * retrying, sent as the `Retry-After` header\n\t * @param options.headers - Further headers the response carries, such as\n\t * a rate limiter's `X-RateLimit-*`\n\t */\n\tconstructor(\n\t\tmessage?: string,\n\t\tretryAfter?: number,\n\t\toptions?: { headers?: Readonly<Record<string, string>> },\n\t) {\n\t\tconst headers = {\n\t\t\t...options?.headers,\n\t\t\t...(retryAfter !== undefined\n\t\t\t\t? { 'Retry-After': String(retryAfter) }\n\t\t\t\t: {}),\n\t\t};\n\t\tsuper(429, message, {\n\t\t\tdetails: retryAfter !== undefined ? { retryAfter } : undefined,\n\t\t\t...(Object.keys(headers).length > 0 ? { headers } : {}),\n\t\t});\n\t\tif (retryAfter !== undefined) this.retryAfter = retryAfter;\n\t}\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\tconstructor(message?: string, details?: any) {\n\t\tsuper(500, message, { details });\n\t}\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\tconstructor(message?: string, details?: any) {\n\t\tsuper(501, message, { details });\n\t}\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\tconstructor(message?: string, details?: any) {\n\t\tsuper(502, message, { details });\n\t}\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\t/**\n\t * @param message - Optional error message\n\t * @param retryAfter - Number of seconds the client should wait before retrying\n\t */\n\tconstructor(message?: string, retryAfter?: number) {\n\t\tsuper(503, message, {\n\t\t\tdetails: retryAfter ? { retryAfter } : undefined,\n\t\t});\n\t}\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\tconstructor(message?: string, details?: any) {\n\t\tsuper(504, message, { details });\n\t}\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\tmessage?: string,\n\tallowedMethods?: 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\tmessage?: string,\n\tvalidationErrors?: any,\n) => UnprocessableEntityError;\n\n/** Discriminated union for all factory types */\ntype ErrorFactory =\n\t| { type: 'standard'; factory: StandardErrorFactory }\n\t| { type: 'methodNotAllowed'; factory: MethodNotAllowedFactory }\n\t| { type: 'retryAfter'; factory: RetryAfterFactory }\n\t| { type: 'validation'; factory: ValidationErrorFactory };\n\n/** Type-safe error registry mapping status codes to their factory functions */\nconst errorRegistry = {\n\t400: {\n\t\ttype: 'standard',\n\t\tfactory: (m: string, d: any) => new BadRequestError(m, d),\n\t},\n\t401: {\n\t\ttype: 'standard',\n\t\tfactory: (m: string, d: any) => new UnauthorizedError(m, d),\n\t},\n\t403: {\n\t\ttype: 'standard',\n\t\tfactory: (m: string, d: any) => new ForbiddenError(m, d),\n\t},\n\t404: {\n\t\ttype: 'standard',\n\t\tfactory: (m: string, d: any) => new NotFoundError(m, d),\n\t},\n\t405: {\n\t\ttype: 'methodNotAllowed',\n\t\tfactory: (m: string, am: string[]) => new MethodNotAllowedError(m, am),\n\t},\n\t409: {\n\t\ttype: 'standard',\n\t\tfactory: (m: string, d: any) => new ConflictError(m, d),\n\t},\n\t422: {\n\t\ttype: 'validation',\n\t\tfactory: (m: string, ve: any) => new UnprocessableEntityError(m, ve),\n\t},\n\t429: {\n\t\ttype: 'retryAfter',\n\t\tfactory: (m: string, ra: number) => new TooManyRequestsError(m, ra),\n\t},\n\t500: {\n\t\ttype: 'standard',\n\t\tfactory: (m: string, d: any) => new InternalServerError(m, d),\n\t},\n\t501: {\n\t\ttype: 'standard',\n\t\tfactory: (m: string, d: any) => new NotImplementedError(m, d),\n\t},\n\t502: {\n\t\ttype: 'standard',\n\t\tfactory: (m: string, d: any) => new BadGatewayError(m, d),\n\t},\n\t503: {\n\t\ttype: 'retryAfter',\n\t\tfactory: (m: string, ra: number) => new ServiceUnavailableError(m, ra),\n\t},\n\t504: {\n\t\ttype: 'standard',\n\t\tfactory: (m: string, d: any) => new GatewayTimeoutError(m, d),\n\t},\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\t? { allowedMethods?: string[]; code?: string; cause?: Error }\n\t: T extends 422\n\t\t? { validationErrors?: any; code?: string; cause?: Error }\n\t\t: T extends 429 | 503\n\t\t\t? { retryAfter?: number; code?: string; cause?: Error }\n\t\t\t: { details?: any; code?: string; cause?: Error };\n\n/** Handler functions for each factory type */\nconst factoryHandlers: Record<\n\tErrorFactory['type'],\n\t(entry: any, message?: string, options?: any) => HttpError\n> = {\n\tstandard: (entry, message, options) =>\n\t\tentry.factory(message, options?.details),\n\tmethodNotAllowed: (entry, message, options) =>\n\t\tentry.factory(message, options?.allowedMethods),\n\tretryAfter: (entry, message, options) =>\n\t\tentry.factory(message, options?.retryAfter),\n\tvalidation: (entry, message, options) =>\n\t\tentry.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\tstatusCode: T,\n\tmessage?: string,\n\toptions?: ErrorOptions<T>,\n): HttpError;\nexport function createHttpError(\n\tstatusCode: number,\n\tmessage?: string,\n\toptions?: HttpErrorOptions,\n): HttpError;\nexport function createHttpError(\n\tstatusCode: number,\n\tmessage?: string,\n\toptions?: any,\n): HttpError {\n\tconst entry = errorRegistry[statusCode as ValidStatusCode];\n\n\tif (entry) {\n\t\tconst handler = factoryHandlers[entry.type];\n\t\treturn handler(entry, message, options);\n\t}\n\n\t// Fallback to generic HttpError for unknown status codes\n\treturn 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\tbadRequest: (message?: string, details?: any) =>\n\t\tnew BadRequestError(message, details),\n\n\tunauthorized: (message?: string, details?: any) =>\n\t\tnew UnauthorizedError(message, details),\n\n\tforbidden: (message?: string, details?: any) =>\n\t\tnew ForbiddenError(message, details),\n\n\tnotFound: (message?: string, details?: any) =>\n\t\tnew NotFoundError(message, details),\n\n\tmethodNotAllowed: (message?: string, allowedMethods?: string[]) =>\n\t\tnew MethodNotAllowedError(message, allowedMethods),\n\n\tconflict: (message?: string, details?: any) =>\n\t\tnew ConflictError(message, details),\n\n\tunprocessableEntity: (message?: string, validationErrors?: any) =>\n\t\tnew UnprocessableEntityError(message, validationErrors),\n\n\ttooManyRequests: (message?: string, retryAfter?: number) =>\n\t\tnew TooManyRequestsError(message, retryAfter),\n\n\tinternalServerError: (message?: string, details?: any) =>\n\t\tnew InternalServerError(message, details),\n\n\tnotImplemented: (message?: string, details?: any) =>\n\t\tnew NotImplementedError(message, details),\n\n\tbadGateway: (message?: string, details?: any) =>\n\t\tnew BadGatewayError(message, details),\n\n\tserviceUnavailable: (message?: string, retryAfter?: number) =>\n\t\tnew ServiceUnavailableError(message, retryAfter),\n\n\tgatewayTimeout: (message?: string, details?: any) =>\n\t\tnew 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\treturn (\n\t\terror instanceof HttpError ||\n\t\t(error !== null &&\n\t\t\ttypeof error === 'object' &&\n\t\t\t'isHttpError' in error &&\n\t\t\terror.isHttpError === true)\n\t);\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\treturn (\n\t\tisHttpError(error) && error.statusCode >= 400 && error.statusCode < 500\n\t);\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\treturn (\n\t\tisHttpError(error) && error.statusCode >= 500 && error.statusCode < 600\n\t);\n}\n\n// Utility functions\n\n/**\n * Wraps an unknown error into an HttpError.\n *\n * One rule: an error that is an HttpError ({@link isHttpError}) passes\n * through unchanged, its status and headers with it; anything else — however\n * it is shaped, a `statusCode` field included — becomes `statusCode` (500 by\n * default). An error that should answer with its own status extends\n * HttpError, so the decision is made where the error is defined rather than\n * guessed from its fields here.\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\terror: unknown,\n\tstatusCode = 500,\n\tmessage?: string,\n): HttpError {\n\tif (isHttpError(error)) {\n\t\treturn error;\n\t}\n\n\treturn new HttpError(statusCode, message || 'An unknown error occurred', {\n\t\tdetails: { originalError: error },\n\t});\n}\n\n// Types for better TypeScript support\n\n/**\n * Options for creating an HttpError.\n */\nexport interface HttpErrorOptions {\n\tstatusMessage?: string;\n\tdetails?: any;\n\tcode?: string;\n\theaders?: Readonly<Record<string, string>>;\n\tcause?: Error;\n}\n\n/**\n * Constructor type for HttpError classes.\n * Useful for factory patterns and dependency injection.\n */\nexport type HttpErrorConstructor = new (\n\tmessage?: string,\n\toptions?: 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\t// 2xx Success\n\tOK = 200,\n\tCREATED = 201,\n\tACCEPTED = 202,\n\tNO_CONTENT = 204,\n\n\t// 3xx Redirection\n\tMOVED_PERMANENTLY = 301,\n\tFOUND = 302,\n\tNOT_MODIFIED = 304,\n\n\t// 4xx Client Error\n\tBAD_REQUEST = 400,\n\tUNAUTHORIZED = 401,\n\tFORBIDDEN = 403,\n\tNOT_FOUND = 404,\n\tMETHOD_NOT_ALLOWED = 405,\n\tNOT_ACCEPTABLE = 406,\n\tREQUEST_TIMEOUT = 408,\n\tCONFLICT = 409,\n\tGONE = 410,\n\tUNPROCESSABLE_ENTITY = 422,\n\tTOO_MANY_REQUESTS = 429,\n\n\t// 5xx Server Error\n\tINTERNAL_SERVER_ERROR = 500,\n\tNOT_IMPLEMENTED = 501,\n\tBAD_GATEWAY = 502,\n\tSERVICE_UNAVAILABLE = 503,\n\tGATEWAY_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\tHttpError,\n\tBadRequestError,\n\tUnauthorizedError,\n\tForbiddenError,\n\tNotFoundError,\n\tMethodNotAllowedError,\n\tConflictError,\n\tUnprocessableEntityError,\n\tTooManyRequestsError,\n\tInternalServerError,\n\tNotImplementedError,\n\tBadGatewayError,\n\tServiceUnavailableError,\n\tGatewayTimeoutError,\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.log('Client made a bad request');\n}\n*/\n"],"mappings":";;;;;;;;;;;;;;;AAeA,IAAa,YAAb,cAA+B,MAAM;;CAEpC;;CAEA;;CAEA,cAA8B;;CAE9B;;CAEA;;;;;;;CAOA;;;;;;;;;;;;;CAcA,YACC,YACA,SACA,SAOC;EACD,MAAM,WAAW,SAAS,iBAAiB,YAAY;EACvD,KAAK,OAAO,KAAK,YAAY;EAC7B,KAAK,aAAa;EAClB,KAAK,gBACJ,SAAS,iBAAiB,KAAK,wBAAwB,UAAU;EAClE,KAAK,UAAU,SAAS;EACxB,KAAK,OAAO,SAAS;EACrB,IAAI,SAAS,SAAS,KAAK,UAAU,QAAQ;EAG7C,IAAI,SAAS,OACZ,KAAK,QAAQ,QAAQ;EAGtB,MAAM,kBAAkB,MAAM,KAAK,WAAW;CAC/C;;;;;;;CAQA,IAAI,OAAO;EACV,OAAO,KAAK,UAAU;GACrB,SAAS,KAAK;GACd,MAAM,KAAK;GACX,OAAO,KAAK;EACb,CAAC;CACF;;;;;;;;CASA,wBAAgC,YAA4B;EAmB3D,OAAO;GAjBN,KAAK;GACL,KAAK;GACL,KAAK;GACL,KAAK;GACL,KAAK;GACL,KAAK;GACL,KAAK;GACL,KAAK;GACL,KAAK;GACL,KAAK;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