@geekmidas/errors 10.0.0-alpha.2 → 10.0.0-alpha.21

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.
@@ -66,7 +66,7 @@ var HttpError = class extends Error {
66
66
  * @private
67
67
  */
68
68
  getDefaultStatusMessage(statusCode) {
69
- const statusMessages = {
69
+ return {
70
70
  400: "Bad Request",
71
71
  401: "Unauthorized",
72
72
  403: "Forbidden",
@@ -83,8 +83,7 @@ var HttpError = class extends Error {
83
83
  502: "Bad Gateway",
84
84
  503: "Service Unavailable",
85
85
  504: "Gateway Timeout"
86
- };
87
- return statusMessages[statusCode] || "Unknown Error";
86
+ }[statusCode] || "Unknown Error";
88
87
  }
89
88
  /**
90
89
  * Serializes the error to a JSON-compatible object.
@@ -507,31 +506,31 @@ function wrapError(error, statusCode = 500, message) {
507
506
  * HTTP status code enum for type-safe status code usage.
508
507
  * Includes common 2xx, 3xx, 4xx, and 5xx status codes.
509
508
  */
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;
509
+ let HttpStatusCode = /* @__PURE__ */ function(HttpStatusCode) {
510
+ HttpStatusCode[HttpStatusCode["OK"] = 200] = "OK";
511
+ HttpStatusCode[HttpStatusCode["CREATED"] = 201] = "CREATED";
512
+ HttpStatusCode[HttpStatusCode["ACCEPTED"] = 202] = "ACCEPTED";
513
+ HttpStatusCode[HttpStatusCode["NO_CONTENT"] = 204] = "NO_CONTENT";
514
+ HttpStatusCode[HttpStatusCode["MOVED_PERMANENTLY"] = 301] = "MOVED_PERMANENTLY";
515
+ HttpStatusCode[HttpStatusCode["FOUND"] = 302] = "FOUND";
516
+ HttpStatusCode[HttpStatusCode["NOT_MODIFIED"] = 304] = "NOT_MODIFIED";
517
+ HttpStatusCode[HttpStatusCode["BAD_REQUEST"] = 400] = "BAD_REQUEST";
518
+ HttpStatusCode[HttpStatusCode["UNAUTHORIZED"] = 401] = "UNAUTHORIZED";
519
+ HttpStatusCode[HttpStatusCode["FORBIDDEN"] = 403] = "FORBIDDEN";
520
+ HttpStatusCode[HttpStatusCode["NOT_FOUND"] = 404] = "NOT_FOUND";
521
+ HttpStatusCode[HttpStatusCode["METHOD_NOT_ALLOWED"] = 405] = "METHOD_NOT_ALLOWED";
522
+ HttpStatusCode[HttpStatusCode["NOT_ACCEPTABLE"] = 406] = "NOT_ACCEPTABLE";
523
+ HttpStatusCode[HttpStatusCode["REQUEST_TIMEOUT"] = 408] = "REQUEST_TIMEOUT";
524
+ HttpStatusCode[HttpStatusCode["CONFLICT"] = 409] = "CONFLICT";
525
+ HttpStatusCode[HttpStatusCode["GONE"] = 410] = "GONE";
526
+ HttpStatusCode[HttpStatusCode["UNPROCESSABLE_ENTITY"] = 422] = "UNPROCESSABLE_ENTITY";
527
+ HttpStatusCode[HttpStatusCode["TOO_MANY_REQUESTS"] = 429] = "TOO_MANY_REQUESTS";
528
+ HttpStatusCode[HttpStatusCode["INTERNAL_SERVER_ERROR"] = 500] = "INTERNAL_SERVER_ERROR";
529
+ HttpStatusCode[HttpStatusCode["NOT_IMPLEMENTED"] = 501] = "NOT_IMPLEMENTED";
530
+ HttpStatusCode[HttpStatusCode["BAD_GATEWAY"] = 502] = "BAD_GATEWAY";
531
+ HttpStatusCode[HttpStatusCode["SERVICE_UNAVAILABLE"] = 503] = "SERVICE_UNAVAILABLE";
532
+ HttpStatusCode[HttpStatusCode["GATEWAY_TIMEOUT"] = 504] = "GATEWAY_TIMEOUT";
533
+ return HttpStatusCode;
535
534
  }({});
536
535
  /**
537
536
  * Namespace containing all HTTP error classes.
@@ -559,7 +558,6 @@ const HttpErrors = {
559
558
  ServiceUnavailableError,
560
559
  GatewayTimeoutError
561
560
  };
562
-
563
561
  //#endregion
564
562
  exports.BadGatewayError = BadGatewayError;
565
563
  exports.BadRequestError = BadRequestError;
@@ -583,4 +581,5 @@ exports.isClientError = isClientError;
583
581
  exports.isHttpError = isHttpError;
584
582
  exports.isServerError = isServerError;
585
583
  exports.wrapError = wrapError;
584
+
586
585
  //# 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\n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G,YACvC,IAAI,oBAAoB,SAAS;CAElC,gBAAgB,CAACH,SAAkBG,YAClC,IAAI,oBAAoB,SAAS;CAElC,YAAY,CAACH,SAAkBG,YAC9B,IAAI,gBAAgB,SAAS;CAE9B,oBAAoB,CAACH,SAAkBM,eACtC,IAAI,wBAAwB,SAAS;CAEtC,gBAAgB,CAACN,SAAkBG,YAClC,IAAI,oBAAoB,SAAS;AAClC;;;;;;;;;;;;;;;;;;;AAsBD,SAAgB,YAAYW,OAAoC;AAC/D,QACC,iBAAiB,aAChB,UAAU,eACH,UAAU,YACjB,iBAAiB,SACjB,MAAM,gBAAgB;AAExB;;;;;;;;;;;;;;AAeD,SAAgB,cAAcA,OAAoC;AACjE,QACC,YAAY,MAAM,IAAI,MAAM,cAAc,OAAO,MAAM,aAAa;AAErE;;;;;;;;;;;;;;AAeD,SAAgB,cAAcA,OAAoC;AACjE,QACC,YAAY,MAAM,IAAI,MAAM,cAAc,OAAO,MAAM,aAAa;AAErE;;;;;;;;;;;;;;;;;;;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\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;;CAEA;;CAEA,cAA8B;;CAE9B;;CAEA;;;;;;;;;;;;CAaA,YACC,YACA,SACA,SAMC;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;EAGrB,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;GACL,KAAK;GACL,KAAK;GACL,KAAK;GACL,KAAK;GACL,KAAK;GACL,KAAK;EAEc,EAAE,eAAe;CACtC;;;;;;;CAQA,SAAS;EACR,OAAO;GACN,MAAM,KAAK;GACX,SAAS,KAAK;GACd,YAAY,KAAK;GACjB,eAAe,KAAK;GACpB,MAAM,KAA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WAAA,OAAA;CACA,eAAA,eAAA,kBAAA,OAAA;CAGA,eAAA,eAAA,iBAAA,OAAA;CACA,eAAA,eAAA,kBAAA,OAAA;CACA,eAAA,eAAA,eAAA,OAAA;CACA,eAAA,eAAA,eAAA,OAAA;CACA,eAAA,eAAA,wBAAA,OAAA;CACA,eAAA,eAAA,oBAAA,OAAA;CACA,eAAA,eAAA,qBAAA,OAAA;CACA,eAAA,eAAA,cAAA,OAAA;CACA,eAAA,eAAA,UAAA,OAAA;CACA,eAAA,eAAA,0BAAA,OAAA;CACA,eAAA,eAAA,uBAAA,OAAA;CAGA,eAAA,eAAA,2BAAA,OAAA;CACA,eAAA,eAAA,qBAAA,OAAA;CACA,eAAA,eAAA,iBAAA,OAAA;CACA,eAAA,eAAA,yBAAA,OAAA;CACA,eAAA,eAAA,qBAAA,OAAA;;AACD,EAAA,CAAA,CAAA;;;;;;;;;;;AAYA,MAAa,aAAa;CACzB;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACD"}
package/dist/index.d.cts CHANGED
@@ -12,7 +12,7 @@
12
12
  * });
13
13
  * ```
14
14
  */
15
- declare class HttpError extends Error {
15
+ export declare class HttpError extends Error {
16
16
  /** The HTTP status code (e.g., 400, 404, 500) */
17
17
  readonly statusCode: number;
18
18
  /** The standard HTTP status message (e.g., 'Bad Request', 'Not Found') */
@@ -82,7 +82,7 @@ declare class HttpError extends Error {
82
82
  * throw new BadRequestError('Invalid JSON', { line: 5, column: 12 });
83
83
  * ```
84
84
  */
85
- declare class BadRequestError extends HttpError {
85
+ export declare class BadRequestError extends HttpError {
86
86
  constructor(message?: string, details?: any);
87
87
  }
88
88
  /**
@@ -96,7 +96,7 @@ declare class BadRequestError extends HttpError {
96
96
  * throw new UnauthorizedError('Invalid token');
97
97
  * ```
98
98
  */
99
- declare class UnauthorizedError extends HttpError {
99
+ export declare class UnauthorizedError extends HttpError {
100
100
  constructor(message?: string, details?: any);
101
101
  }
102
102
  /**
@@ -110,7 +110,7 @@ declare class UnauthorizedError extends HttpError {
110
110
  * throw new ForbiddenError('Insufficient permissions', { required: 'admin' });
111
111
  * ```
112
112
  */
113
- declare class ForbiddenError extends HttpError {
113
+ export declare class ForbiddenError extends HttpError {
114
114
  constructor(message?: string, details?: any);
115
115
  }
116
116
  /**
@@ -124,7 +124,7 @@ declare class ForbiddenError extends HttpError {
124
124
  * throw new NotFoundError('User not found', { userId: '123' });
125
125
  * ```
126
126
  */
127
- declare class NotFoundError extends HttpError {
127
+ export declare class NotFoundError extends HttpError {
128
128
  constructor(message?: string, details?: any);
129
129
  }
130
130
  /**
@@ -138,7 +138,7 @@ declare class NotFoundError extends HttpError {
138
138
  * throw new MethodNotAllowedError('DELETE not supported', ['GET', 'POST', 'PUT']);
139
139
  * ```
140
140
  */
141
- declare class MethodNotAllowedError extends HttpError {
141
+ export declare class MethodNotAllowedError extends HttpError {
142
142
  /**
143
143
  * @param message - Optional error message
144
144
  * @param allowedMethods - Array of allowed HTTP methods for this resource
@@ -156,7 +156,7 @@ declare class MethodNotAllowedError extends HttpError {
156
156
  * throw new ConflictError('Email already exists', { email: 'user@example.com' });
157
157
  * ```
158
158
  */
159
- declare class ConflictError extends HttpError {
159
+ export declare class ConflictError extends HttpError {
160
160
  constructor(message?: string, details?: any);
161
161
  }
162
162
  /**
@@ -173,7 +173,7 @@ declare class ConflictError extends HttpError {
173
173
  * });
174
174
  * ```
175
175
  */
176
- declare class UnprocessableEntityError extends HttpError {
176
+ export declare class UnprocessableEntityError extends HttpError {
177
177
  /**
178
178
  * @param message - Optional error message
179
179
  * @param validationErrors - Object containing field-specific validation errors
@@ -191,7 +191,7 @@ declare class UnprocessableEntityError extends HttpError {
191
191
  * throw new TooManyRequestsError('Rate limit exceeded', 60); // retry after 60 seconds
192
192
  * ```
193
193
  */
194
- declare class TooManyRequestsError extends HttpError {
194
+ export declare class TooManyRequestsError extends HttpError {
195
195
  /**
196
196
  * @param message - Optional error message
197
197
  * @param retryAfter - Number of seconds the client should wait before retrying
@@ -209,7 +209,7 @@ declare class TooManyRequestsError extends HttpError {
209
209
  * throw new InternalServerError('Database connection failed');
210
210
  * ```
211
211
  */
212
- declare class InternalServerError extends HttpError {
212
+ export declare class InternalServerError extends HttpError {
213
213
  constructor(message?: string, details?: any);
214
214
  }
215
215
  /**
@@ -223,7 +223,7 @@ declare class InternalServerError extends HttpError {
223
223
  * throw new NotImplementedError('WebSocket support not implemented');
224
224
  * ```
225
225
  */
226
- declare class NotImplementedError extends HttpError {
226
+ export declare class NotImplementedError extends HttpError {
227
227
  constructor(message?: string, details?: any);
228
228
  }
229
229
  /**
@@ -237,7 +237,7 @@ declare class NotImplementedError extends HttpError {
237
237
  * throw new BadGatewayError('Upstream server error');
238
238
  * ```
239
239
  */
240
- declare class BadGatewayError extends HttpError {
240
+ export declare class BadGatewayError extends HttpError {
241
241
  constructor(message?: string, details?: any);
242
242
  }
243
243
  /**
@@ -251,7 +251,7 @@ declare class BadGatewayError extends HttpError {
251
251
  * throw new ServiceUnavailableError('Maintenance in progress', 300); // retry after 5 minutes
252
252
  * ```
253
253
  */
254
- declare class ServiceUnavailableError extends HttpError {
254
+ export declare class ServiceUnavailableError extends HttpError {
255
255
  /**
256
256
  * @param message - Optional error message
257
257
  * @param retryAfter - Number of seconds the client should wait before retrying
@@ -269,61 +269,61 @@ declare class ServiceUnavailableError extends HttpError {
269
269
  * throw new GatewayTimeoutError('Upstream server timeout');
270
270
  * ```
271
271
  */
272
- declare class GatewayTimeoutError extends HttpError {
272
+ export declare class GatewayTimeoutError extends HttpError {
273
273
  constructor(message?: string, details?: any);
274
274
  }
275
275
  /** Type-safe error registry mapping status codes to their factory functions */
276
276
  declare const errorRegistry: {
277
277
  readonly 400: {
278
- readonly type: "standard";
278
+ readonly type: 'standard';
279
279
  readonly factory: (m: string, d: any) => BadRequestError;
280
280
  };
281
281
  readonly 401: {
282
- readonly type: "standard";
282
+ readonly type: 'standard';
283
283
  readonly factory: (m: string, d: any) => UnauthorizedError;
284
284
  };
285
285
  readonly 403: {
286
- readonly type: "standard";
286
+ readonly type: 'standard';
287
287
  readonly factory: (m: string, d: any) => ForbiddenError;
288
288
  };
289
289
  readonly 404: {
290
- readonly type: "standard";
290
+ readonly type: 'standard';
291
291
  readonly factory: (m: string, d: any) => NotFoundError;
292
292
  };
293
293
  readonly 405: {
294
- readonly type: "methodNotAllowed";
294
+ readonly type: 'methodNotAllowed';
295
295
  readonly factory: (m: string, am: string[]) => MethodNotAllowedError;
296
296
  };
297
297
  readonly 409: {
298
- readonly type: "standard";
298
+ readonly type: 'standard';
299
299
  readonly factory: (m: string, d: any) => ConflictError;
300
300
  };
301
301
  readonly 422: {
302
- readonly type: "validation";
302
+ readonly type: 'validation';
303
303
  readonly factory: (m: string, ve: any) => UnprocessableEntityError;
304
304
  };
305
305
  readonly 429: {
306
- readonly type: "retryAfter";
306
+ readonly type: 'retryAfter';
307
307
  readonly factory: (m: string, ra: number) => TooManyRequestsError;
308
308
  };
309
309
  readonly 500: {
310
- readonly type: "standard";
310
+ readonly type: 'standard';
311
311
  readonly factory: (m: string, d: any) => InternalServerError;
312
312
  };
313
313
  readonly 501: {
314
- readonly type: "standard";
314
+ readonly type: 'standard';
315
315
  readonly factory: (m: string, d: any) => NotImplementedError;
316
316
  };
317
317
  readonly 502: {
318
- readonly type: "standard";
318
+ readonly type: 'standard';
319
319
  readonly factory: (m: string, d: any) => BadGatewayError;
320
320
  };
321
321
  readonly 503: {
322
- readonly type: "retryAfter";
322
+ readonly type: 'retryAfter';
323
323
  readonly factory: (m: string, ra: number) => ServiceUnavailableError;
324
324
  };
325
325
  readonly 504: {
326
- readonly type: "standard";
326
+ readonly type: 'standard';
327
327
  readonly factory: (m: string, d: any) => GatewayTimeoutError;
328
328
  };
329
329
  };
@@ -366,8 +366,8 @@ type ErrorOptions<T extends number> = T extends 405 ? {
366
366
  * createHttpError(429, 'Rate limited', { retryAfter: 60 });
367
367
  * ```
368
368
  */
369
- declare function createHttpError<T extends ValidStatusCode>(statusCode: T, message?: string, options?: ErrorOptions<T>): HttpError;
370
- declare function createHttpError(statusCode: number, message?: string, options?: HttpErrorOptions): HttpError;
369
+ export declare function createHttpError<T extends ValidStatusCode>(statusCode: T, message?: string, options?: ErrorOptions<T>): HttpError;
370
+ export declare function createHttpError(statusCode: number, message?: string, options?: HttpErrorOptions): HttpError;
371
371
  /**
372
372
  * Type-safe error creation utilities with descriptive method names.
373
373
  * Provides a fluent API for creating specific HTTP errors.
@@ -379,7 +379,7 @@ declare function createHttpError(statusCode: number, message?: string, options?:
379
379
  * createError.methodNotAllowed('DELETE not supported', ['GET', 'POST']);
380
380
  * ```
381
381
  */
382
- declare const createError: {
382
+ export declare const createError: {
383
383
  readonly badRequest: (message?: string, details?: any) => BadRequestError;
384
384
  readonly unauthorized: (message?: string, details?: any) => UnauthorizedError;
385
385
  readonly forbidden: (message?: string, details?: any) => ForbiddenError;
@@ -412,7 +412,7 @@ declare const createError: {
412
412
  * }
413
413
  * ```
414
414
  */
415
- declare function isHttpError(error: unknown): error is HttpError;
415
+ export declare function isHttpError(error: unknown): error is HttpError;
416
416
  /**
417
417
  * Type guard to check if an error is a client error (4xx status code).
418
418
  *
@@ -426,7 +426,7 @@ declare function isHttpError(error: unknown): error is HttpError;
426
426
  * }
427
427
  * ```
428
428
  */
429
- declare function isClientError(error: unknown): error is HttpError;
429
+ export declare function isClientError(error: unknown): error is HttpError;
430
430
  /**
431
431
  * Type guard to check if an error is a server error (5xx status code).
432
432
  *
@@ -440,7 +440,7 @@ declare function isClientError(error: unknown): error is HttpError;
440
440
  * }
441
441
  * ```
442
442
  */
443
- declare function isServerError(error: unknown): error is HttpError;
443
+ export declare function isServerError(error: unknown): error is HttpError;
444
444
  /**
445
445
  * Wraps an unknown error into an HttpError.
446
446
  * If the error is already an HttpError, returns it unchanged.
@@ -459,11 +459,11 @@ declare function isServerError(error: unknown): error is HttpError;
459
459
  * }
460
460
  * ```
461
461
  */
462
- declare function wrapError(error: unknown, statusCode?: number, message?: string): HttpError;
462
+ export declare function wrapError(error: unknown, statusCode?: number, message?: string): HttpError;
463
463
  /**
464
464
  * Options for creating an HttpError.
465
465
  */
466
- interface HttpErrorOptions {
466
+ export interface HttpErrorOptions {
467
467
  statusMessage?: string;
468
468
  details?: any;
469
469
  code?: string;
@@ -473,12 +473,12 @@ interface HttpErrorOptions {
473
473
  * Constructor type for HttpError classes.
474
474
  * Useful for factory patterns and dependency injection.
475
475
  */
476
- type HttpErrorConstructor = new (message?: string, options?: HttpErrorOptions) => HttpError;
476
+ export type HttpErrorConstructor = new (message?: string, options?: HttpErrorOptions) => HttpError;
477
477
  /**
478
478
  * HTTP status code enum for type-safe status code usage.
479
479
  * Includes common 2xx, 3xx, 4xx, and 5xx status codes.
480
480
  */
481
- declare enum HttpStatusCode {
481
+ export declare enum HttpStatusCode {
482
482
  OK = 200,
483
483
  CREATED = 201,
484
484
  ACCEPTED = 202,
@@ -501,7 +501,7 @@ declare enum HttpStatusCode {
501
501
  NOT_IMPLEMENTED = 501,
502
502
  BAD_GATEWAY = 502,
503
503
  SERVICE_UNAVAILABLE = 503,
504
- GATEWAY_TIMEOUT = 504,
504
+ GATEWAY_TIMEOUT = 504
505
505
  }
506
506
  /**
507
507
  * Namespace containing all HTTP error classes.
@@ -513,7 +513,7 @@ declare enum HttpStatusCode {
513
513
  * throw new HttpErrors.NotFoundError('Resource not found');
514
514
  * ```
515
515
  */
516
- declare const HttpErrors: {
516
+ export declare const HttpErrors: {
517
517
  HttpError: typeof HttpError;
518
518
  BadRequestError: typeof BadRequestError;
519
519
  UnauthorizedError: typeof UnauthorizedError;
@@ -530,5 +530,4 @@ declare const HttpErrors: {
530
530
  GatewayTimeoutError: typeof GatewayTimeoutError;
531
531
  };
532
532
  //#endregion
533
- export { BadGatewayError, BadRequestError, ConflictError, ForbiddenError, GatewayTimeoutError, HttpError, HttpErrorConstructor, HttpErrorOptions, HttpErrors, HttpStatusCode, InternalServerError, MethodNotAllowedError, NotFoundError, NotImplementedError, ServiceUnavailableError, TooManyRequestsError, UnauthorizedError, UnprocessableEntityError, createError, createHttpError, isClientError, isHttpError, isServerError, wrapError };
534
533
  //# sourceMappingURL=index.d.cts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.cts","names":[],"sources":["../src/index.ts"],"sourcesContent":[],"mappings":";;AAeA;;;;AAAoC;AA4HpC;AAiBA;AAiBA;AAiBA;AAiBA;AAuBA;AAoBA;AAuBa,cAlQA,SAAA,SAAkB,KAAA,CAkQW;EAyB7B;EAiBA,SAAA,UAAA,EAAA,MAAoB;EAiBpB;EAiBA,SAAA,aAAA,EAAA,MAAwB;EAuBxB;EA+BP,SAAA,WAqDI,GAAA,IAAA;EAAA;EAAA,SAlDmB,OAAA,CAAA,EAAA,GAAA;EAAA;EAIA,SAIA,IAAA,CAAA,EAAA,MAAA;EAAA;;;;;;;;;;AAwCA;EAKxB,WAAA,CAAA,UAAe,EAAA,MAAgB,EAAA,OAAa,CAAb,EAAa,MAAA,EAAA,OAIW,CAJX,EAAA;IAG5C,aAAY,CAAA,EAAA,MAAA;IAAA,OAAA,CAAA,EAAA,GAAA;IAAqB,IAAA,CAAA,EAAA,MAAA;IACiB,KAAA,CAAA,EAla5C,KAka4C;EAAK,CAAA;EACxD;;;;AAI8C;AAoClD;EAA+B,IAAA,IAAA,CAAA,CAAA,EAAA,MAAA;EAAA;;;;;AAInB;AACZ;EAA+B,QAAA,uBAAA;EAAA;;AAInB;AA4BZ;;;EAC6C,MAGE,CAAA,CAAA,EAAA;IAGH,IAAA,EAAA,MAAA;IAGD,OAAA,EAAA,MAAA;IAGoB,UAAA,EAAA,MAAA;IAGpB,aAAA,EAAA,MAAA;IAGoB,IAAA,EAAA,MAAA,GAAA,SAAA;IAGP,OAAA,EAAA,GAAA;IAGF,KAAA,EAAA,MAAA,GAAA,SAAA;EAAA,CAAA;;;;AAYL;AAwBjD;AAuBA;AAmBA;AA0BA;AAuBA;AAWA;;;AAGK,cAxjBQ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;;;;;;;;;;;wBAmBxC,cAAc,iBAAiB,SAAS;;;;;;;;;;;;;;;;;;;wBA0BxC,UACf,gBACA,qBACA,mBACE;;;;iBAmBc;EAChB;EACA;EACA;EACA,QAAQ;;;;;;YAOG,4BACX,kBACA,UAAU,qBACN;;;;;oBAMO;EAEX;EACA;EACA;EACA;EAGA;EACA;EACA;EAGA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EAGA;EACA;EACA;EACA;EACA;;;;;;;;;;;;qBAaY"}
package/dist/index.d.mts CHANGED
@@ -12,7 +12,7 @@
12
12
  * });
13
13
  * ```
14
14
  */
15
- declare class HttpError extends Error {
15
+ export declare class HttpError extends Error {
16
16
  /** The HTTP status code (e.g., 400, 404, 500) */
17
17
  readonly statusCode: number;
18
18
  /** The standard HTTP status message (e.g., 'Bad Request', 'Not Found') */
@@ -82,7 +82,7 @@ declare class HttpError extends Error {
82
82
  * throw new BadRequestError('Invalid JSON', { line: 5, column: 12 });
83
83
  * ```
84
84
  */
85
- declare class BadRequestError extends HttpError {
85
+ export declare class BadRequestError extends HttpError {
86
86
  constructor(message?: string, details?: any);
87
87
  }
88
88
  /**
@@ -96,7 +96,7 @@ declare class BadRequestError extends HttpError {
96
96
  * throw new UnauthorizedError('Invalid token');
97
97
  * ```
98
98
  */
99
- declare class UnauthorizedError extends HttpError {
99
+ export declare class UnauthorizedError extends HttpError {
100
100
  constructor(message?: string, details?: any);
101
101
  }
102
102
  /**
@@ -110,7 +110,7 @@ declare class UnauthorizedError extends HttpError {
110
110
  * throw new ForbiddenError('Insufficient permissions', { required: 'admin' });
111
111
  * ```
112
112
  */
113
- declare class ForbiddenError extends HttpError {
113
+ export declare class ForbiddenError extends HttpError {
114
114
  constructor(message?: string, details?: any);
115
115
  }
116
116
  /**
@@ -124,7 +124,7 @@ declare class ForbiddenError extends HttpError {
124
124
  * throw new NotFoundError('User not found', { userId: '123' });
125
125
  * ```
126
126
  */
127
- declare class NotFoundError extends HttpError {
127
+ export declare class NotFoundError extends HttpError {
128
128
  constructor(message?: string, details?: any);
129
129
  }
130
130
  /**
@@ -138,7 +138,7 @@ declare class NotFoundError extends HttpError {
138
138
  * throw new MethodNotAllowedError('DELETE not supported', ['GET', 'POST', 'PUT']);
139
139
  * ```
140
140
  */
141
- declare class MethodNotAllowedError extends HttpError {
141
+ export declare class MethodNotAllowedError extends HttpError {
142
142
  /**
143
143
  * @param message - Optional error message
144
144
  * @param allowedMethods - Array of allowed HTTP methods for this resource
@@ -156,7 +156,7 @@ declare class MethodNotAllowedError extends HttpError {
156
156
  * throw new ConflictError('Email already exists', { email: 'user@example.com' });
157
157
  * ```
158
158
  */
159
- declare class ConflictError extends HttpError {
159
+ export declare class ConflictError extends HttpError {
160
160
  constructor(message?: string, details?: any);
161
161
  }
162
162
  /**
@@ -173,7 +173,7 @@ declare class ConflictError extends HttpError {
173
173
  * });
174
174
  * ```
175
175
  */
176
- declare class UnprocessableEntityError extends HttpError {
176
+ export declare class UnprocessableEntityError extends HttpError {
177
177
  /**
178
178
  * @param message - Optional error message
179
179
  * @param validationErrors - Object containing field-specific validation errors
@@ -191,7 +191,7 @@ declare class UnprocessableEntityError extends HttpError {
191
191
  * throw new TooManyRequestsError('Rate limit exceeded', 60); // retry after 60 seconds
192
192
  * ```
193
193
  */
194
- declare class TooManyRequestsError extends HttpError {
194
+ export declare class TooManyRequestsError extends HttpError {
195
195
  /**
196
196
  * @param message - Optional error message
197
197
  * @param retryAfter - Number of seconds the client should wait before retrying
@@ -209,7 +209,7 @@ declare class TooManyRequestsError extends HttpError {
209
209
  * throw new InternalServerError('Database connection failed');
210
210
  * ```
211
211
  */
212
- declare class InternalServerError extends HttpError {
212
+ export declare class InternalServerError extends HttpError {
213
213
  constructor(message?: string, details?: any);
214
214
  }
215
215
  /**
@@ -223,7 +223,7 @@ declare class InternalServerError extends HttpError {
223
223
  * throw new NotImplementedError('WebSocket support not implemented');
224
224
  * ```
225
225
  */
226
- declare class NotImplementedError extends HttpError {
226
+ export declare class NotImplementedError extends HttpError {
227
227
  constructor(message?: string, details?: any);
228
228
  }
229
229
  /**
@@ -237,7 +237,7 @@ declare class NotImplementedError extends HttpError {
237
237
  * throw new BadGatewayError('Upstream server error');
238
238
  * ```
239
239
  */
240
- declare class BadGatewayError extends HttpError {
240
+ export declare class BadGatewayError extends HttpError {
241
241
  constructor(message?: string, details?: any);
242
242
  }
243
243
  /**
@@ -251,7 +251,7 @@ declare class BadGatewayError extends HttpError {
251
251
  * throw new ServiceUnavailableError('Maintenance in progress', 300); // retry after 5 minutes
252
252
  * ```
253
253
  */
254
- declare class ServiceUnavailableError extends HttpError {
254
+ export declare class ServiceUnavailableError extends HttpError {
255
255
  /**
256
256
  * @param message - Optional error message
257
257
  * @param retryAfter - Number of seconds the client should wait before retrying
@@ -269,61 +269,61 @@ declare class ServiceUnavailableError extends HttpError {
269
269
  * throw new GatewayTimeoutError('Upstream server timeout');
270
270
  * ```
271
271
  */
272
- declare class GatewayTimeoutError extends HttpError {
272
+ export declare class GatewayTimeoutError extends HttpError {
273
273
  constructor(message?: string, details?: any);
274
274
  }
275
275
  /** Type-safe error registry mapping status codes to their factory functions */
276
276
  declare const errorRegistry: {
277
277
  readonly 400: {
278
- readonly type: "standard";
278
+ readonly type: 'standard';
279
279
  readonly factory: (m: string, d: any) => BadRequestError;
280
280
  };
281
281
  readonly 401: {
282
- readonly type: "standard";
282
+ readonly type: 'standard';
283
283
  readonly factory: (m: string, d: any) => UnauthorizedError;
284
284
  };
285
285
  readonly 403: {
286
- readonly type: "standard";
286
+ readonly type: 'standard';
287
287
  readonly factory: (m: string, d: any) => ForbiddenError;
288
288
  };
289
289
  readonly 404: {
290
- readonly type: "standard";
290
+ readonly type: 'standard';
291
291
  readonly factory: (m: string, d: any) => NotFoundError;
292
292
  };
293
293
  readonly 405: {
294
- readonly type: "methodNotAllowed";
294
+ readonly type: 'methodNotAllowed';
295
295
  readonly factory: (m: string, am: string[]) => MethodNotAllowedError;
296
296
  };
297
297
  readonly 409: {
298
- readonly type: "standard";
298
+ readonly type: 'standard';
299
299
  readonly factory: (m: string, d: any) => ConflictError;
300
300
  };
301
301
  readonly 422: {
302
- readonly type: "validation";
302
+ readonly type: 'validation';
303
303
  readonly factory: (m: string, ve: any) => UnprocessableEntityError;
304
304
  };
305
305
  readonly 429: {
306
- readonly type: "retryAfter";
306
+ readonly type: 'retryAfter';
307
307
  readonly factory: (m: string, ra: number) => TooManyRequestsError;
308
308
  };
309
309
  readonly 500: {
310
- readonly type: "standard";
310
+ readonly type: 'standard';
311
311
  readonly factory: (m: string, d: any) => InternalServerError;
312
312
  };
313
313
  readonly 501: {
314
- readonly type: "standard";
314
+ readonly type: 'standard';
315
315
  readonly factory: (m: string, d: any) => NotImplementedError;
316
316
  };
317
317
  readonly 502: {
318
- readonly type: "standard";
318
+ readonly type: 'standard';
319
319
  readonly factory: (m: string, d: any) => BadGatewayError;
320
320
  };
321
321
  readonly 503: {
322
- readonly type: "retryAfter";
322
+ readonly type: 'retryAfter';
323
323
  readonly factory: (m: string, ra: number) => ServiceUnavailableError;
324
324
  };
325
325
  readonly 504: {
326
- readonly type: "standard";
326
+ readonly type: 'standard';
327
327
  readonly factory: (m: string, d: any) => GatewayTimeoutError;
328
328
  };
329
329
  };
@@ -366,8 +366,8 @@ type ErrorOptions<T extends number> = T extends 405 ? {
366
366
  * createHttpError(429, 'Rate limited', { retryAfter: 60 });
367
367
  * ```
368
368
  */
369
- declare function createHttpError<T extends ValidStatusCode>(statusCode: T, message?: string, options?: ErrorOptions<T>): HttpError;
370
- declare function createHttpError(statusCode: number, message?: string, options?: HttpErrorOptions): HttpError;
369
+ export declare function createHttpError<T extends ValidStatusCode>(statusCode: T, message?: string, options?: ErrorOptions<T>): HttpError;
370
+ export declare function createHttpError(statusCode: number, message?: string, options?: HttpErrorOptions): HttpError;
371
371
  /**
372
372
  * Type-safe error creation utilities with descriptive method names.
373
373
  * Provides a fluent API for creating specific HTTP errors.
@@ -379,7 +379,7 @@ declare function createHttpError(statusCode: number, message?: string, options?:
379
379
  * createError.methodNotAllowed('DELETE not supported', ['GET', 'POST']);
380
380
  * ```
381
381
  */
382
- declare const createError: {
382
+ export declare const createError: {
383
383
  readonly badRequest: (message?: string, details?: any) => BadRequestError;
384
384
  readonly unauthorized: (message?: string, details?: any) => UnauthorizedError;
385
385
  readonly forbidden: (message?: string, details?: any) => ForbiddenError;
@@ -412,7 +412,7 @@ declare const createError: {
412
412
  * }
413
413
  * ```
414
414
  */
415
- declare function isHttpError(error: unknown): error is HttpError;
415
+ export declare function isHttpError(error: unknown): error is HttpError;
416
416
  /**
417
417
  * Type guard to check if an error is a client error (4xx status code).
418
418
  *
@@ -426,7 +426,7 @@ declare function isHttpError(error: unknown): error is HttpError;
426
426
  * }
427
427
  * ```
428
428
  */
429
- declare function isClientError(error: unknown): error is HttpError;
429
+ export declare function isClientError(error: unknown): error is HttpError;
430
430
  /**
431
431
  * Type guard to check if an error is a server error (5xx status code).
432
432
  *
@@ -440,7 +440,7 @@ declare function isClientError(error: unknown): error is HttpError;
440
440
  * }
441
441
  * ```
442
442
  */
443
- declare function isServerError(error: unknown): error is HttpError;
443
+ export declare function isServerError(error: unknown): error is HttpError;
444
444
  /**
445
445
  * Wraps an unknown error into an HttpError.
446
446
  * If the error is already an HttpError, returns it unchanged.
@@ -459,11 +459,11 @@ declare function isServerError(error: unknown): error is HttpError;
459
459
  * }
460
460
  * ```
461
461
  */
462
- declare function wrapError(error: unknown, statusCode?: number, message?: string): HttpError;
462
+ export declare function wrapError(error: unknown, statusCode?: number, message?: string): HttpError;
463
463
  /**
464
464
  * Options for creating an HttpError.
465
465
  */
466
- interface HttpErrorOptions {
466
+ export interface HttpErrorOptions {
467
467
  statusMessage?: string;
468
468
  details?: any;
469
469
  code?: string;
@@ -473,12 +473,12 @@ interface HttpErrorOptions {
473
473
  * Constructor type for HttpError classes.
474
474
  * Useful for factory patterns and dependency injection.
475
475
  */
476
- type HttpErrorConstructor = new (message?: string, options?: HttpErrorOptions) => HttpError;
476
+ export type HttpErrorConstructor = new (message?: string, options?: HttpErrorOptions) => HttpError;
477
477
  /**
478
478
  * HTTP status code enum for type-safe status code usage.
479
479
  * Includes common 2xx, 3xx, 4xx, and 5xx status codes.
480
480
  */
481
- declare enum HttpStatusCode {
481
+ export declare enum HttpStatusCode {
482
482
  OK = 200,
483
483
  CREATED = 201,
484
484
  ACCEPTED = 202,
@@ -501,7 +501,7 @@ declare enum HttpStatusCode {
501
501
  NOT_IMPLEMENTED = 501,
502
502
  BAD_GATEWAY = 502,
503
503
  SERVICE_UNAVAILABLE = 503,
504
- GATEWAY_TIMEOUT = 504,
504
+ GATEWAY_TIMEOUT = 504
505
505
  }
506
506
  /**
507
507
  * Namespace containing all HTTP error classes.
@@ -513,7 +513,7 @@ declare enum HttpStatusCode {
513
513
  * throw new HttpErrors.NotFoundError('Resource not found');
514
514
  * ```
515
515
  */
516
- declare const HttpErrors: {
516
+ export declare const HttpErrors: {
517
517
  HttpError: typeof HttpError;
518
518
  BadRequestError: typeof BadRequestError;
519
519
  UnauthorizedError: typeof UnauthorizedError;
@@ -530,5 +530,4 @@ declare const HttpErrors: {
530
530
  GatewayTimeoutError: typeof GatewayTimeoutError;
531
531
  };
532
532
  //#endregion
533
- export { BadGatewayError, BadRequestError, ConflictError, ForbiddenError, GatewayTimeoutError, HttpError, HttpErrorConstructor, HttpErrorOptions, HttpErrors, HttpStatusCode, InternalServerError, MethodNotAllowedError, NotFoundError, NotImplementedError, ServiceUnavailableError, TooManyRequestsError, UnauthorizedError, UnprocessableEntityError, createError, createHttpError, isClientError, isHttpError, isServerError, wrapError };
534
533
  //# sourceMappingURL=index.d.mts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.mts","names":[],"sources":["../src/index.ts"],"sourcesContent":[],"mappings":";;AAeA;;;;AAAoC;AA4HpC;AAiBA;AAiBA;AAiBA;AAiBA;AAuBA;AAoBA;AAuBa,cAlQA,SAAA,SAAkB,KAAA,CAkQW;EA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ist/index.mjs CHANGED
@@ -65,7 +65,7 @@ var HttpError = class extends Error {
65
65
  * @private
66
66
  */
67
67
  getDefaultStatusMessage(statusCode) {
68
- const statusMessages = {
68
+ return {
69
69
  400: "Bad Request",
70
70
  401: "Unauthorized",
71
71
  403: "Forbidden",
@@ -82,8 +82,7 @@ var HttpError = class extends Error {
82
82
  502: "Bad Gateway",
83
83
  503: "Service Unavailable",
84
84
  504: "Gateway Timeout"
85
- };
86
- return statusMessages[statusCode] || "Unknown Error";
85
+ }[statusCode] || "Unknown Error";
87
86
  }
88
87
  /**
89
88
  * Serializes the error to a JSON-compatible object.
@@ -506,31 +505,31 @@ function wrapError(error, statusCode = 500, message) {
506
505
  * HTTP status code enum for type-safe status code usage.
507
506
  * Includes common 2xx, 3xx, 4xx, and 5xx status codes.
508
507
  */
509
- let HttpStatusCode = /* @__PURE__ */ function(HttpStatusCode$1) {
510
- HttpStatusCode$1[HttpStatusCode$1["OK"] = 200] = "OK";
511
- HttpStatusCode$1[HttpStatusCode$1["CREATED"] = 201] = "CREATED";
512
- HttpStatusCode$1[HttpStatusCode$1["ACCEPTED"] = 202] = "ACCEPTED";
513
- HttpStatusCode$1[HttpStatusCode$1["NO_CONTENT"] = 204] = "NO_CONTENT";
514
- HttpStatusCode$1[HttpStatusCode$1["MOVED_PERMANENTLY"] = 301] = "MOVED_PERMANENTLY";
515
- HttpStatusCode$1[HttpStatusCode$1["FOUND"] = 302] = "FOUND";
516
- HttpStatusCode$1[HttpStatusCode$1["NOT_MODIFIED"] = 304] = "NOT_MODIFIED";
517
- HttpStatusCode$1[HttpStatusCode$1["BAD_REQUEST"] = 400] = "BAD_REQUEST";
518
- HttpStatusCode$1[HttpStatusCode$1["UNAUTHORIZED"] = 401] = "UNAUTHORIZED";
519
- HttpStatusCode$1[HttpStatusCode$1["FORBIDDEN"] = 403] = "FORBIDDEN";
520
- HttpStatusCode$1[HttpStatusCode$1["NOT_FOUND"] = 404] = "NOT_FOUND";
521
- HttpStatusCode$1[HttpStatusCode$1["METHOD_NOT_ALLOWED"] = 405] = "METHOD_NOT_ALLOWED";
522
- HttpStatusCode$1[HttpStatusCode$1["NOT_ACCEPTABLE"] = 406] = "NOT_ACCEPTABLE";
523
- HttpStatusCode$1[HttpStatusCode$1["REQUEST_TIMEOUT"] = 408] = "REQUEST_TIMEOUT";
524
- HttpStatusCode$1[HttpStatusCode$1["CONFLICT"] = 409] = "CONFLICT";
525
- HttpStatusCode$1[HttpStatusCode$1["GONE"] = 410] = "GONE";
526
- HttpStatusCode$1[HttpStatusCode$1["UNPROCESSABLE_ENTITY"] = 422] = "UNPROCESSABLE_ENTITY";
527
- HttpStatusCode$1[HttpStatusCode$1["TOO_MANY_REQUESTS"] = 429] = "TOO_MANY_REQUESTS";
528
- HttpStatusCode$1[HttpStatusCode$1["INTERNAL_SERVER_ERROR"] = 500] = "INTERNAL_SERVER_ERROR";
529
- HttpStatusCode$1[HttpStatusCode$1["NOT_IMPLEMENTED"] = 501] = "NOT_IMPLEMENTED";
530
- HttpStatusCode$1[HttpStatusCode$1["BAD_GATEWAY"] = 502] = "BAD_GATEWAY";
531
- HttpStatusCode$1[HttpStatusCode$1["SERVICE_UNAVAILABLE"] = 503] = "SERVICE_UNAVAILABLE";
532
- HttpStatusCode$1[HttpStatusCode$1["GATEWAY_TIMEOUT"] = 504] = "GATEWAY_TIMEOUT";
533
- return HttpStatusCode$1;
508
+ let HttpStatusCode = /* @__PURE__ */ function(HttpStatusCode) {
509
+ HttpStatusCode[HttpStatusCode["OK"] = 200] = "OK";
510
+ HttpStatusCode[HttpStatusCode["CREATED"] = 201] = "CREATED";
511
+ HttpStatusCode[HttpStatusCode["ACCEPTED"] = 202] = "ACCEPTED";
512
+ HttpStatusCode[HttpStatusCode["NO_CONTENT"] = 204] = "NO_CONTENT";
513
+ HttpStatusCode[HttpStatusCode["MOVED_PERMANENTLY"] = 301] = "MOVED_PERMANENTLY";
514
+ HttpStatusCode[HttpStatusCode["FOUND"] = 302] = "FOUND";
515
+ HttpStatusCode[HttpStatusCode["NOT_MODIFIED"] = 304] = "NOT_MODIFIED";
516
+ HttpStatusCode[HttpStatusCode["BAD_REQUEST"] = 400] = "BAD_REQUEST";
517
+ HttpStatusCode[HttpStatusCode["UNAUTHORIZED"] = 401] = "UNAUTHORIZED";
518
+ HttpStatusCode[HttpStatusCode["FORBIDDEN"] = 403] = "FORBIDDEN";
519
+ HttpStatusCode[HttpStatusCode["NOT_FOUND"] = 404] = "NOT_FOUND";
520
+ HttpStatusCode[HttpStatusCode["METHOD_NOT_ALLOWED"] = 405] = "METHOD_NOT_ALLOWED";
521
+ HttpStatusCode[HttpStatusCode["NOT_ACCEPTABLE"] = 406] = "NOT_ACCEPTABLE";
522
+ HttpStatusCode[HttpStatusCode["REQUEST_TIMEOUT"] = 408] = "REQUEST_TIMEOUT";
523
+ HttpStatusCode[HttpStatusCode["CONFLICT"] = 409] = "CONFLICT";
524
+ HttpStatusCode[HttpStatusCode["GONE"] = 410] = "GONE";
525
+ HttpStatusCode[HttpStatusCode["UNPROCESSABLE_ENTITY"] = 422] = "UNPROCESSABLE_ENTITY";
526
+ HttpStatusCode[HttpStatusCode["TOO_MANY_REQUESTS"] = 429] = "TOO_MANY_REQUESTS";
527
+ HttpStatusCode[HttpStatusCode["INTERNAL_SERVER_ERROR"] = 500] = "INTERNAL_SERVER_ERROR";
528
+ HttpStatusCode[HttpStatusCode["NOT_IMPLEMENTED"] = 501] = "NOT_IMPLEMENTED";
529
+ HttpStatusCode[HttpStatusCode["BAD_GATEWAY"] = 502] = "BAD_GATEWAY";
530
+ HttpStatusCode[HttpStatusCode["SERVICE_UNAVAILABLE"] = 503] = "SERVICE_UNAVAILABLE";
531
+ HttpStatusCode[HttpStatusCode["GATEWAY_TIMEOUT"] = 504] = "GATEWAY_TIMEOUT";
532
+ return HttpStatusCode;
534
533
  }({});
535
534
  /**
536
535
  * Namespace containing all HTTP error classes.
@@ -558,7 +557,7 @@ const HttpErrors = {
558
557
  ServiceUnavailableError,
559
558
  GatewayTimeoutError
560
559
  };
561
-
562
560
  //#endregion
563
561
  export { BadGatewayError, BadRequestError, ConflictError, ForbiddenError, GatewayTimeoutError, HttpError, HttpErrors, HttpStatusCode, InternalServerError, MethodNotAllowedError, NotFoundError, NotImplementedError, ServiceUnavailableError, TooManyRequestsError, UnauthorizedError, UnprocessableEntityError, createError, createHttpError, isClientError, isHttpError, isServerError, wrapError };
562
+
564
563
  //# sourceMappingURL=index.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.mjs","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,YACA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AACN,SAAkBG,YAClC,IAAI,oBAAoB,SAAS;AAClC;;;;;;;;;;;;;;;;;;;AAsBD,SAAgB,YAAYW,OAAoC;AAC/D,QACC,iBAAiB,aAChB,UAAU,eACH,UAAU,YACjB,iBAAiB,SACjB,MAAM,gBAAgB;AAExB;;;;;;;;;;;;;;AAeD,SAAgB,cAAcA,OAAoC;AACjE,QACC,YAAY,MAAM,IAAI,MAAM,cAAc,OAAO,MAAM,aAAa;AAErE;;;;;;;;;;;;;;AAeD,SAAgB,cAAcA,OAAoC;AACjE,QACC,YAAY,MAAM,IAAI,MAAM,cAAc,OAAO,MAAM,aAAa;AAErE;;;;;;;;;;;;;;;;;;;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.mjs","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\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;;CAEA;;CAEA,cAA8B;;CAE9B;;CAEA;;;;;;;;;;;;CAaA,YACC,YACA,SACA,SAMC;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;EAGrB,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;GACL,KAAK;GACL,KAAK;GACL,KAAK;GACL,KAAK;GACL,KAAK;GACL,KAAK;EAEc,EAAE,eAAe;CACtC;;;;;;;CAQA,SAAS;EACR,OAAO;GACN,MAAM,KAAK;GACX,SAAS,KAAK;GACd,YAAY,KAAK;GACjB,eAAe,KAAK;GACpB,MAAM,KAAK;GACX,SAAS,KAAK;GACd,OAAO,KAAK;EACb;CACD;AACD;;;;;;;;;;;;AAeA,IAAa,kBAAb,cAAqC,UAAU;CAC9C,YAAY,SAAkB,SAAe;EAC5C,MAAM,KAAK,SAAS,EAAE,QAAQ,CAAC;CAChC;AACD;;;;;;;;;;;;AAaA,IAAa,oBAAb,cA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A,OAAA;CACA,eAAA,eAAA,qBAAA,OAAA;CACA,eAAA,eAAA,cAAA,OAAA;CACA,eAAA,eAAA,UAAA,OAAA;CACA,eAAA,eAAA,0BAAA,OAAA;CACA,eAAA,eAAA,uBAAA,OAAA;CAGA,eAAA,eAAA,2BAAA,OAAA;CACA,eAAA,eAAA,qBAAA,OAAA;CACA,eAAA,eAAA,iBAAA,OAAA;CACA,eAAA,eAAA,yBAAA,OAAA;CACA,eAAA,eAAA,qBAAA,OAAA;;AACD,EAAA,CAAA,CAAA;;;;;;;;;;;AAYA,MAAa,aAAa;CACzB;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACD"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@geekmidas/errors",
3
- "version": "10.0.0-alpha.2",
3
+ "version": "10.0.0-alpha.21",
4
4
  "type": "module",
5
5
  "exports": {
6
6
  ".": {