@geekmidas/errors 0.1.0 → 1.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md ADDED
@@ -0,0 +1,13 @@
1
+ # @geekmidas/errors
2
+
3
+ ## 1.0.1
4
+
5
+ ### Patch Changes
6
+
7
+ - 🐛 [`d70c6c0`](https://github.com/geekmidas/toolbox/commit/d70c6c0aeb8a79da2473ac77dbd8255a4a2f5651) Thanks [@geekmidas](https://github.com/geekmidas)! - Fix `package.json` exports so TypeScript declarations resolve correctly under NodeNext/Bundler module resolution. Each subpath export now nests `types` inside its `import`/`require` condition, pointing at the `.d.mts` and `.d.cts` files that `tsdown` actually emits (previously the exports referenced non-existent `.d.ts` files, causing type-resolution failures for consumers). Both ESM (`.mjs`) and CJS (`.cjs`) runtime entry points are preserved. Additionally, `@geekmidas/ui` had `import` paths pointing at `.js` files that were never emitted — those are corrected to `.mjs`.
8
+
9
+ ## 1.0.0
10
+
11
+ ### Major Changes
12
+
13
+ - [`ff7b115`](https://github.com/geekmidas/toolbox/commit/ff7b11599f60f84ac6cdc73714c853ecf786b2e8) Thanks [@geekmidas](https://github.com/geekmidas)! - Version 1 Stable release
@@ -1 +1 @@
1
- {"version":3,"file":"index.cjs","names":["statusCode: number","message?: string","options?: {\n statusMessage?: string;\n details?: any;\n code?: string;\n cause?: Error;\n }","statusMessages: Record<number, string>","details?: any","allowedMethods?: string[]","validationErrors?: any","retryAfter?: number","m: string","d: any","am: string[]","ve: any","ra: number","factoryHandlers: Record<\n ErrorFactory['type'],\n (entry: any, message?: string, options?: any) => HttpError\n>","options?: any","error: unknown"],"sources":["../src/index.ts"],"sourcesContent":["// http-errors.ts - Core HTTP Error Classes and Types\n\n/**\n * Base HTTP Error class that extends the native Error.\n * Provides a foundation for all HTTP-specific errors with status codes and structured error responses.\n *\n * @extends Error\n *\n * @example\n * ```typescript\n * throw new HttpError(400, 'Bad Request', {\n * details: { field: 'email', message: 'Invalid format' }\n * });\n * ```\n */\nexport class HttpError extends Error {\n /** The HTTP status code (e.g., 400, 404, 500) */\n public readonly statusCode: number;\n /** The standard HTTP status message (e.g., 'Bad Request', 'Not Found') */\n public readonly statusMessage: string;\n /** Type discriminator for runtime type checking */\n public readonly isHttpError = true;\n /** Additional error details for debugging or client information */\n public readonly details?: any;\n /** Application-specific error code for client-side handling */\n public readonly code?: string;\n\n /**\n * Creates a new HttpError instance.\n *\n * @param statusCode - The HTTP status code\n * @param message - Optional error message for the client\n * @param options - Optional configuration object\n * @param options.statusMessage - Override the default status message\n * @param options.details - Additional error details or context\n * @param options.code - Application-specific error code\n * @param options.cause - The underlying error that caused this error (ES2022)\n */\n constructor(\n statusCode: number,\n message?: string,\n options?: {\n statusMessage?: string;\n details?: any;\n code?: string;\n cause?: Error;\n },\n ) {\n super(message || options?.statusMessage || 'HTTP Error');\n this.name = this.constructor.name;\n this.statusCode = statusCode;\n this.statusMessage =\n options?.statusMessage || this.getDefaultStatusMessage(statusCode);\n this.details = options?.details;\n this.code = options?.code;\n\n // Set cause if provided (ES2022 feature)\n if (options?.cause) {\n this.cause = options.cause;\n }\n // @ts-ignore\n // Maintains proper stack trace for where our error was thrown\n Error.captureStackTrace(this, this.constructor);\n }\n\n /**\n * Gets the error response body as a JSON string.\n * Used for sending the error response to clients.\n *\n * @returns JSON string containing message, code, and error details\n */\n get body() {\n return JSON.stringify({\n message: this.message,\n code: this.code,\n error: this.details,\n });\n }\n\n /**\n * Gets the default HTTP status message for a given status code.\n *\n * @param statusCode - The HTTP status code\n * @returns The standard HTTP status message or 'Unknown Error' if not found\n * @private\n */\n private getDefaultStatusMessage(statusCode: number): string {\n const statusMessages: Record<number, string> = {\n 400: 'Bad Request',\n 401: 'Unauthorized',\n 403: 'Forbidden',\n 404: 'Not Found',\n 405: 'Method Not Allowed',\n 406: 'Not Acceptable',\n 408: 'Request Timeout',\n 409: 'Conflict',\n 410: 'Gone',\n 422: 'Unprocessable Entity',\n 429: 'Too Many Requests',\n 500: 'Internal Server Error',\n 501: 'Not Implemented',\n 502: 'Bad Gateway',\n 503: 'Service Unavailable',\n 504: 'Gateway Timeout',\n };\n return statusMessages[statusCode] || 'Unknown Error';\n }\n\n /**\n * Serializes the error to a JSON-compatible object.\n * Useful for logging and debugging purposes.\n *\n * @returns Object representation of the error including stack trace\n */\n toJSON() {\n return {\n name: this.name,\n message: this.message,\n statusCode: this.statusCode,\n statusMessage: this.statusMessage,\n code: this.code,\n details: this.details,\n stack: this.stack,\n };\n }\n}\n\n// Client Error Classes (4xx)\n\n/**\n * Represents a 400 Bad Request error.\n * Used when the client sends a malformed or invalid request.\n *\n * @extends HttpError\n *\n * @example\n * ```typescript\n * throw new BadRequestError('Invalid JSON', { line: 5, column: 12 });\n * ```\n */\nexport class BadRequestError extends HttpError {\n constructor(message?: string, details?: any) {\n super(400, message, { details });\n }\n}\n\n/**\n * Represents a 401 Unauthorized error.\n * Used when authentication is required but not provided or invalid.\n *\n * @extends HttpError\n *\n * @example\n * ```typescript\n * throw new UnauthorizedError('Invalid token');\n * ```\n */\nexport class UnauthorizedError extends HttpError {\n constructor(message?: string, details?: any) {\n super(401, message, { details });\n }\n}\n\n/**\n * Represents a 403 Forbidden error.\n * Used when the client is authenticated but lacks permission for the resource.\n *\n * @extends HttpError\n *\n * @example\n * ```typescript\n * throw new ForbiddenError('Insufficient permissions', { required: 'admin' });\n * ```\n */\nexport class ForbiddenError extends HttpError {\n constructor(message?: string, details?: any) {\n super(403, message, { details });\n }\n}\n\n/**\n * Represents a 404 Not Found error.\n * Used when the requested resource doesn't exist.\n *\n * @extends HttpError\n *\n * @example\n * ```typescript\n * throw new NotFoundError('User not found', { userId: '123' });\n * ```\n */\nexport class NotFoundError extends HttpError {\n constructor(message?: string, details?: any) {\n super(404, message, { details });\n }\n}\n\n/**\n * Represents a 405 Method Not Allowed error.\n * Used when the HTTP method is not supported for the requested resource.\n *\n * @extends HttpError\n *\n * @example\n * ```typescript\n * throw new MethodNotAllowedError('DELETE not supported', ['GET', 'POST', 'PUT']);\n * ```\n */\nexport class MethodNotAllowedError extends HttpError {\n /**\n * @param message - Optional error message\n * @param allowedMethods - Array of allowed HTTP methods for this resource\n */\n constructor(message?: string, allowedMethods?: string[]) {\n super(405, message, {\n details: allowedMethods ? { allowedMethods } : undefined,\n });\n }\n}\n\n/**\n * Represents a 409 Conflict error.\n * Used when the request conflicts with the current state of the resource.\n *\n * @extends HttpError\n *\n * @example\n * ```typescript\n * throw new ConflictError('Email already exists', { email: 'user@example.com' });\n * ```\n */\nexport class ConflictError extends HttpError {\n constructor(message?: string, details?: any) {\n super(409, message, { details });\n }\n}\n\n/**\n * Represents a 422 Unprocessable Entity error.\n * Used when the request is well-formed but contains semantic errors.\n *\n * @extends HttpError\n *\n * @example\n * ```typescript\n * throw new UnprocessableEntityError('Validation failed', {\n * email: 'Invalid format',\n * age: 'Must be 18 or older'\n * });\n * ```\n */\nexport class UnprocessableEntityError extends HttpError {\n /**\n * @param message - Optional error message\n * @param validationErrors - Object containing field-specific validation errors\n */\n constructor(message?: string, validationErrors?: any) {\n super(422, message, {\n details: validationErrors ? { validationErrors } : undefined,\n });\n }\n}\n\n/**\n * Represents a 429 Too Many Requests error.\n * Used when the client has exceeded rate limits.\n *\n * @extends HttpError\n *\n * @example\n * ```typescript\n * throw new TooManyRequestsError('Rate limit exceeded', 60); // retry after 60 seconds\n * ```\n */\nexport class TooManyRequestsError extends HttpError {\n /**\n * @param message - Optional error message\n * @param retryAfter - Number of seconds the client should wait before retrying\n */\n constructor(message?: string, retryAfter?: number) {\n super(429, message, {\n details: retryAfter ? { retryAfter } : undefined,\n });\n }\n}\n\n// Server Error Classes (5xx)\n\n/**\n * Represents a 500 Internal Server Error.\n * Used for unexpected server-side errors.\n *\n * @extends HttpError\n *\n * @example\n * ```typescript\n * throw new InternalServerError('Database connection failed');\n * ```\n */\nexport class InternalServerError extends HttpError {\n constructor(message?: string, details?: any) {\n super(500, message, { details });\n }\n}\n\n/**\n * Represents a 501 Not Implemented error.\n * Used when the server doesn't support the requested functionality.\n *\n * @extends HttpError\n *\n * @example\n * ```typescript\n * throw new NotImplementedError('WebSocket support not implemented');\n * ```\n */\nexport class NotImplementedError extends HttpError {\n constructor(message?: string, details?: any) {\n super(501, message, { details });\n }\n}\n\n/**\n * Represents a 502 Bad Gateway error.\n * Used when the server receives an invalid response from an upstream server.\n *\n * @extends HttpError\n *\n * @example\n * ```typescript\n * throw new BadGatewayError('Upstream server error');\n * ```\n */\nexport class BadGatewayError extends HttpError {\n constructor(message?: string, details?: any) {\n super(502, message, { details });\n }\n}\n\n/**\n * Represents a 503 Service Unavailable error.\n * Used when the server is temporarily unable to handle requests.\n *\n * @extends HttpError\n *\n * @example\n * ```typescript\n * throw new ServiceUnavailableError('Maintenance in progress', 300); // retry after 5 minutes\n * ```\n */\nexport class ServiceUnavailableError extends HttpError {\n /**\n * @param message - Optional error message\n * @param retryAfter - Number of seconds the client should wait before retrying\n */\n constructor(message?: string, retryAfter?: number) {\n super(503, message, {\n details: retryAfter ? { retryAfter } : undefined,\n });\n }\n}\n\n/**\n * Represents a 504 Gateway Timeout error.\n * Used when the server doesn't receive a timely response from an upstream server.\n *\n * @extends HttpError\n *\n * @example\n * ```typescript\n * throw new GatewayTimeoutError('Upstream server timeout');\n * ```\n */\nexport class GatewayTimeoutError extends HttpError {\n constructor(message?: string, details?: any) {\n super(504, message, { details });\n }\n}\n\n// Type definitions for different error factory signatures\n\n/** Factory function for standard HTTP errors with optional details */\ntype StandardErrorFactory = (message?: string, details?: any) => HttpError;\n/** Factory function for Method Not Allowed errors with allowed methods */\ntype MethodNotAllowedFactory = (\n message?: string,\n allowedMethods?: string[],\n) => MethodNotAllowedError;\n/** Factory function for errors that include retry-after information */\ntype RetryAfterFactory = (message?: string, retryAfter?: number) => HttpError;\n/** Factory function for validation errors with field-specific errors */\ntype ValidationErrorFactory = (\n message?: string,\n validationErrors?: any,\n) => UnprocessableEntityError;\n\n/** Discriminated union for all factory types */\ntype ErrorFactory =\n | { type: 'standard'; factory: StandardErrorFactory }\n | { type: 'methodNotAllowed'; factory: MethodNotAllowedFactory }\n | { type: 'retryAfter'; factory: RetryAfterFactory }\n | { type: 'validation'; factory: ValidationErrorFactory };\n\n/** Type-safe error registry mapping status codes to their factory functions */\nconst errorRegistry = {\n 400: {\n type: 'standard',\n factory: (m: string, d: any) => new BadRequestError(m, d),\n },\n 401: {\n type: 'standard',\n factory: (m: string, d: any) => new UnauthorizedError(m, d),\n },\n 403: {\n type: 'standard',\n factory: (m: string, d: any) => new ForbiddenError(m, d),\n },\n 404: {\n type: 'standard',\n factory: (m: string, d: any) => new NotFoundError(m, d),\n },\n 405: {\n type: 'methodNotAllowed',\n factory: (m: string, am: string[]) => new MethodNotAllowedError(m, am),\n },\n 409: {\n type: 'standard',\n factory: (m: string, d: any) => new ConflictError(m, d),\n },\n 422: {\n type: 'validation',\n factory: (m: string, ve: any) => new UnprocessableEntityError(m, ve),\n },\n 429: {\n type: 'retryAfter',\n factory: (m: string, ra: number) => new TooManyRequestsError(m, ra),\n },\n 500: {\n type: 'standard',\n factory: (m: string, d: any) => new InternalServerError(m, d),\n },\n 501: {\n type: 'standard',\n factory: (m: string, d: any) => new NotImplementedError(m, d),\n },\n 502: {\n type: 'standard',\n factory: (m: string, d: any) => new BadGatewayError(m, d),\n },\n 503: {\n type: 'retryAfter',\n factory: (m: string, ra: number) => new ServiceUnavailableError(m, ra),\n },\n 504: {\n type: 'standard',\n factory: (m: string, d: any) => new GatewayTimeoutError(m, d),\n },\n} as const;\n\n/** Valid status codes that have registered error factories */\ntype ValidStatusCode = keyof typeof errorRegistry;\n\n/** Type-safe options based on status code, ensuring correct parameters for each error type */\ntype ErrorOptions<T extends number> = T extends 405\n ? { allowedMethods?: string[]; code?: string; cause?: Error }\n : T extends 422\n ? { validationErrors?: any; code?: string; cause?: Error }\n : T extends 429 | 503\n ? { retryAfter?: number; code?: string; cause?: Error }\n : { details?: any; code?: string; cause?: Error };\n\n/** Handler functions for each factory type */\nconst factoryHandlers: Record<\n ErrorFactory['type'],\n (entry: any, message?: string, options?: any) => HttpError\n> = {\n standard: (entry, message, options) =>\n entry.factory(message, options?.details),\n methodNotAllowed: (entry, message, options) =>\n entry.factory(message, options?.allowedMethods),\n retryAfter: (entry, message, options) =>\n entry.factory(message, options?.retryAfter),\n validation: (entry, message, options) =>\n entry.factory(message, options?.validationErrors),\n};\n\n/**\n * Creates an HTTP error with type-safe options based on the status code.\n * Provides IntelliSense support for status-code-specific options.\n *\n * @overload For known status codes with specific options\n * @param statusCode - A valid HTTP status code from the registry\n * @param message - Optional error message\n * @param options - Status-code-specific options\n * @returns The appropriate HttpError subclass\n *\n * @example\n * ```typescript\n * // TypeScript knows allowedMethods is valid for 405\n * createHttpError(405, 'Method not allowed', { allowedMethods: ['GET', 'POST'] });\n *\n * // TypeScript knows retryAfter is valid for 429\n * createHttpError(429, 'Rate limited', { retryAfter: 60 });\n * ```\n */\nexport function createHttpError<T extends ValidStatusCode>(\n statusCode: T,\n message?: string,\n options?: ErrorOptions<T>,\n): HttpError;\nexport function createHttpError(\n statusCode: number,\n message?: string,\n options?: HttpErrorOptions,\n): HttpError;\nexport function createHttpError(\n statusCode: number,\n message?: string,\n options?: any,\n): HttpError {\n const entry = errorRegistry[statusCode as ValidStatusCode];\n\n if (entry) {\n const handler = factoryHandlers[entry.type];\n return handler(entry, message, options);\n }\n\n // Fallback to generic HttpError for unknown status codes\n return new HttpError(statusCode, message, options);\n}\n\n/**\n * Type-safe error creation utilities with descriptive method names.\n * Provides a fluent API for creating specific HTTP errors.\n *\n * @example\n * ```typescript\n * createError.notFound('User not found');\n * createError.badRequest('Invalid input', { field: 'email' });\n * createError.methodNotAllowed('DELETE not supported', ['GET', 'POST']);\n * ```\n */\nexport const createError = {\n badRequest: (message?: string, details?: any) =>\n new BadRequestError(message, details),\n\n unauthorized: (message?: string, details?: any) =>\n new UnauthorizedError(message, details),\n\n forbidden: (message?: string, details?: any) =>\n new ForbiddenError(message, details),\n\n notFound: (message?: string, details?: any) =>\n new NotFoundError(message, details),\n\n methodNotAllowed: (message?: string, allowedMethods?: string[]) =>\n new MethodNotAllowedError(message, allowedMethods),\n\n conflict: (message?: string, details?: any) =>\n new ConflictError(message, details),\n\n unprocessableEntity: (message?: string, validationErrors?: any) =>\n new UnprocessableEntityError(message, validationErrors),\n\n tooManyRequests: (message?: string, retryAfter?: number) =>\n new TooManyRequestsError(message, retryAfter),\n\n internalServerError: (message?: string, details?: any) =>\n new InternalServerError(message, details),\n\n notImplemented: (message?: string, details?: any) =>\n new NotImplementedError(message, details),\n\n badGateway: (message?: string, details?: any) =>\n new BadGatewayError(message, details),\n\n serviceUnavailable: (message?: string, retryAfter?: number) =>\n new ServiceUnavailableError(message, retryAfter),\n\n gatewayTimeout: (message?: string, details?: any) =>\n new GatewayTimeoutError(message, details),\n} as const;\n\n// Type guards\n\n/**\n * Type guard to check if an error is an HttpError.\n * Works with both instanceof checks and duck typing.\n *\n * @param error - The error to check\n * @returns True if the error is an HttpError\n *\n * @example\n * ```typescript\n * try {\n * // some code\n * } catch (error) {\n * if (isHttpError(error)) {\n * console.log(`HTTP ${error.statusCode}: ${error.message}`);\n * }\n * }\n * ```\n */\nexport function isHttpError(error: unknown): error is HttpError {\n return (\n error instanceof HttpError ||\n (error !== null &&\n typeof error === 'object' &&\n 'isHttpError' in error &&\n error.isHttpError === true)\n );\n}\n\n/**\n * Type guard to check if an error is a client error (4xx status code).\n *\n * @param error - The error to check\n * @returns True if the error is an HttpError with a 4xx status code\n *\n * @example\n * ```typescript\n * if (isClientError(error)) {\n * // Log client error metrics\n * }\n * ```\n */\nexport function isClientError(error: unknown): error is HttpError {\n return (\n isHttpError(error) && error.statusCode >= 400 && error.statusCode < 500\n );\n}\n\n/**\n * Type guard to check if an error is a server error (5xx status code).\n *\n * @param error - The error to check\n * @returns True if the error is an HttpError with a 5xx status code\n *\n * @example\n * ```typescript\n * if (isServerError(error)) {\n * // Trigger alerts for server errors\n * }\n * ```\n */\nexport function isServerError(error: unknown): error is HttpError {\n return (\n isHttpError(error) && error.statusCode >= 500 && error.statusCode < 600\n );\n}\n\n// Utility functions\n\n/**\n * Wraps an unknown error into an HttpError.\n * If the error is already an HttpError, returns it unchanged.\n *\n * @param error - The error to wrap\n * @param statusCode - The HTTP status code to use (defaults to 500)\n * @param message - Optional message to override the original error message\n * @returns An HttpError instance\n *\n * @example\n * ```typescript\n * try {\n * await someOperation();\n * } catch (error) {\n * throw wrapError(error, 503, 'Service temporarily unavailable');\n * }\n * ```\n */\nexport function wrapError(\n error: unknown,\n statusCode = 500,\n message?: string,\n): HttpError {\n if (isHttpError(error)) {\n return error;\n }\n\n if (error instanceof HttpError) {\n return error;\n }\n\n return new HttpError(statusCode, message || 'An unknown error occurred', {\n details: { originalError: error },\n });\n}\n\n// Types for better TypeScript support\n\n/**\n * Options for creating an HttpError.\n */\nexport interface HttpErrorOptions {\n statusMessage?: string;\n details?: any;\n code?: string;\n cause?: Error;\n}\n\n/**\n * Constructor type for HttpError classes.\n * Useful for factory patterns and dependency injection.\n */\nexport type HttpErrorConstructor = new (\n message?: string,\n options?: HttpErrorOptions,\n) => HttpError;\n\n/**\n * HTTP status code enum for type-safe status code usage.\n * Includes common 2xx, 3xx, 4xx, and 5xx status codes.\n */\nexport enum HttpStatusCode {\n // 2xx Success\n OK = 200,\n CREATED = 201,\n ACCEPTED = 202,\n NO_CONTENT = 204,\n\n // 3xx Redirection\n MOVED_PERMANENTLY = 301,\n FOUND = 302,\n NOT_MODIFIED = 304,\n\n // 4xx Client Error\n BAD_REQUEST = 400,\n UNAUTHORIZED = 401,\n FORBIDDEN = 403,\n NOT_FOUND = 404,\n METHOD_NOT_ALLOWED = 405,\n NOT_ACCEPTABLE = 406,\n REQUEST_TIMEOUT = 408,\n CONFLICT = 409,\n GONE = 410,\n UNPROCESSABLE_ENTITY = 422,\n TOO_MANY_REQUESTS = 429,\n\n // 5xx Server Error\n INTERNAL_SERVER_ERROR = 500,\n NOT_IMPLEMENTED = 501,\n BAD_GATEWAY = 502,\n SERVICE_UNAVAILABLE = 503,\n GATEWAY_TIMEOUT = 504,\n}\n\n/**\n * Namespace containing all HTTP error classes.\n * Useful for importing all error types at once.\n *\n * @example\n * ```typescript\n * import { HttpErrors } from '@geekmidas/errors';\n * throw new HttpErrors.NotFoundError('Resource not found');\n * ```\n */\nexport const HttpErrors = {\n HttpError,\n BadRequestError,\n UnauthorizedError,\n ForbiddenError,\n NotFoundError,\n MethodNotAllowedError,\n ConflictError,\n UnprocessableEntityError,\n TooManyRequestsError,\n InternalServerError,\n NotImplementedError,\n BadGatewayError,\n ServiceUnavailableError,\n GatewayTimeoutError,\n};\n\n// Usage examples:\n/*\n// Basic usage\nthrow new NotFoundError('User not found');\nthrow new BadRequestError('Invalid email format', { field: 'email' });\n\n// With validation errors\nthrow new UnprocessableEntityError('Validation failed', {\n email: 'Invalid email format',\n password: 'Password must be at least 8 characters',\n});\n\n// Type-safe factory function with IntelliSense support\nthrow createHttpError(405, 'Method not allowed', { \n allowedMethods: ['GET', 'POST'] // TypeScript knows this is the correct option!\n});\n\nthrow createHttpError(429, 'Too many requests', { \n retryAfter: 60 // TypeScript knows this needs retryAfter, not details!\n});\n\nthrow createHttpError(422, 'Validation failed', {\n validationErrors: { // TypeScript knows this is for validation errors\n email: 'Invalid format',\n age: 'Must be 18+'\n }\n});\n\n// Using the type-safe createError object\nthrow createError.methodNotAllowed('DELETE not supported', ['GET', 'POST']);\nthrow createError.tooManyRequests('Rate limit exceeded', 60);\nthrow createError.unprocessableEntity('Invalid input', {\n field: 'email',\n message: 'Invalid format'\n});\n\n// TypeScript will show errors for incorrect usage:\n// throw createHttpError(404, 'Not found', { retryAfter: 60 }); // ❌ Type error!\n// throw createError.notFound('User not found', 60); // ❌ Type error!\n\n// Wrapping unknown errors\ntry {\n await someAsyncOperation();\n} catch (error) {\n throw wrapError(error, 500, 'Failed to process request');\n}\n\n// In Express middleware\napp.use(expressErrorHandler);\n\n// Type checking\nif (isClientError(error)) {\n console.log('Client made a bad request');\n}\n*/\n"],"mappings":";;;;;;;;;;;;;;;AAeA,IAAa,YAAb,cAA+B,MAAM;;CAEnC,AAAgB;;CAEhB,AAAgB;;CAEhB,AAAgB,cAAc;;CAE9B,AAAgB;;CAEhB,AAAgB;;;;;;;;;;;;CAahB,YACEA,YACAC,SACAC,SAMA;AACA,QAAM,WAAW,SAAS,iBAAiB,aAAa;AACxD,OAAK,OAAO,KAAK,YAAY;AAC7B,OAAK,aAAa;AAClB,OAAK,gBACH,SAAS,iBAAiB,KAAK,wBAAwB,WAAW;AACpE,OAAK,UAAU,SAAS;AACxB,OAAK,OAAO,SAAS;AAGrB,MAAI,SAAS,MACX,MAAK,QAAQ,QAAQ;AAIvB,QAAM,kBAAkB,MAAM,KAAK,YAAY;CAChD;;;;;;;CAQD,IAAI,OAAO;AACT,SAAO,KAAK,UAAU;GACpB,SAAS,KAAK;GACd,MAAM,KAAK;GACX,OAAO,KAAK;EACb,EAAC;CACH;;;;;;;;CASD,AAAQ,wBAAwBF,YAA4B;EAC1D,MAAMG,iBAAyC;GAC7C,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;EACN;AACD,SAAO,eAAe,eAAe;CACtC;;;;;;;CAQD,SAAS;AACP,SAAO;GACL,MAAM,KAAK;GACX,SAAS,KAAK;GACd,YAAY,KAAK;GACjB,eAAe,KAAK;GACpB,MAAM,KAAK;GACX,SAAS,KAAK;GACd,OAAO,KAAK;EACb;CACF;AACF;;;;;;;;;;;;AAeD,IAAa,kBAAb,cAAqC,UAAU;CAC7C,YAAYF,SAAkBG,SAAe;AAC3C,QAAM,KAAK,SAAS,EAAE,QAAS,EAAC;CACjC;AACF;;;;;;;;;;;;AAaD,IAAa,oBAAb,cAAuC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I,oBAAoB,SAAS;CAEnC,gBAAgB,CAACH,SAAkBG,YACjC,IAAI,oBAAoB,SAAS;CAEnC,YAAY,CAACH,SAAkBG,YAC7B,IAAI,gBAAgB,SAAS;CAE/B,oBAAoB,CAACH,SAAkBM,eACrC,IAAI,wBAAwB,SAAS;CAEvC,gBAAgB,CAACN,SAAkBG,YACjC,IAAI,oBAAoB,SAAS;AACpC;;;;;;;;;;;;;;;;;;;AAsBD,SAAgB,YAAYW,OAAoC;AAC9D,QACE,iBAAiB,aAChB,UAAU,eACF,UAAU,YACjB,iBAAiB,SACjB,MAAM,gBAAgB;AAE3B;;;;;;;;;;;;;;AAeD,SAAgB,cAAcA,OAAoC;AAChE,QACE,YAAY,MAAM,IAAI,MAAM,cAAc,OAAO,MAAM,aAAa;AAEvE;;;;;;;;;;;;;;AAeD,SAAgB,cAAcA,OAAoC;AAChE,QACE,YAAY,MAAM,IAAI,MAAM,cAAc,OAAO,MAAM,aAAa;AAEvE;;;;;;;;;;;;;;;;;;;AAsBD,SAAgB,UACdA,OACA,aAAa,KACbd,SACW;AACX,KAAI,YAAY,MAAM,CACpB,QAAO;AAGT,KAAI,iBAAiB,UACnB,QAAO;AAGT,QAAO,IAAI,UAAU,YAAY,WAAW,6BAA6B,EACvE,SAAS,EAAE,eAAe,MAAO,EAClC;AACF;;;;;AA2BD,IAAY,4DAAL;AAEL;AACA;AACA;AACA;AAGA;AACA;AACA;AAGA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAGA;AACA;AACA;AACA;AACA;;AACD;;;;;;;;;;;AAYD,MAAa,aAAa;CACxB;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACD"}
1
+ {"version":3,"file":"index.cjs","names":["statusCode: number","message?: string","options?: {\n\t\t\tstatusMessage?: string;\n\t\t\tdetails?: any;\n\t\t\tcode?: string;\n\t\t\tcause?: Error;\n\t\t}","statusMessages: Record<number, string>","details?: any","allowedMethods?: string[]","validationErrors?: any","retryAfter?: number","m: string","d: any","am: string[]","ve: any","ra: number","factoryHandlers: Record<\n\tErrorFactory['type'],\n\t(entry: any, message?: string, options?: any) => HttpError\n>","options?: any","error: unknown"],"sources":["../src/index.ts"],"sourcesContent":["// http-errors.ts - Core HTTP Error Classes and Types\n\n/**\n * Base HTTP Error class that extends the native Error.\n * Provides a foundation for all HTTP-specific errors with status codes and structured error responses.\n *\n * @extends Error\n *\n * @example\n * ```typescript\n * throw new HttpError(400, 'Bad Request', {\n * details: { field: 'email', message: 'Invalid format' }\n * });\n * ```\n */\nexport class HttpError extends Error {\n\t/** The HTTP status code (e.g., 400, 404, 500) */\n\tpublic readonly statusCode: number;\n\t/** The standard HTTP status message (e.g., 'Bad Request', 'Not Found') */\n\tpublic readonly statusMessage: string;\n\t/** Type discriminator for runtime type checking */\n\tpublic readonly isHttpError = true;\n\t/** Additional error details for debugging or client information */\n\tpublic readonly details?: any;\n\t/** Application-specific error code for client-side handling */\n\tpublic readonly code?: string;\n\n\t/**\n\t * Creates a new HttpError instance.\n\t *\n\t * @param statusCode - The HTTP status code\n\t * @param message - Optional error message for the client\n\t * @param options - Optional configuration object\n\t * @param options.statusMessage - Override the default status message\n\t * @param options.details - Additional error details or context\n\t * @param options.code - Application-specific error code\n\t * @param options.cause - The underlying error that caused this error (ES2022)\n\t */\n\tconstructor(\n\t\tstatusCode: number,\n\t\tmessage?: string,\n\t\toptions?: {\n\t\t\tstatusMessage?: string;\n\t\t\tdetails?: any;\n\t\t\tcode?: string;\n\t\t\tcause?: Error;\n\t\t},\n\t) {\n\t\tsuper(message || options?.statusMessage || 'HTTP Error');\n\t\tthis.name = this.constructor.name;\n\t\tthis.statusCode = statusCode;\n\t\tthis.statusMessage =\n\t\t\toptions?.statusMessage || this.getDefaultStatusMessage(statusCode);\n\t\tthis.details = options?.details;\n\t\tthis.code = options?.code;\n\n\t\t// Set cause if provided (ES2022 feature)\n\t\tif (options?.cause) {\n\t\t\tthis.cause = options.cause;\n\t\t}\n\t\t// Maintains proper stack trace for where our error was thrown\n\t\tError.captureStackTrace(this, this.constructor);\n\t}\n\n\t/**\n\t * Gets the error response body as a JSON string.\n\t * Used for sending the error response to clients.\n\t *\n\t * @returns JSON string containing message, code, and error details\n\t */\n\tget body() {\n\t\treturn JSON.stringify({\n\t\t\tmessage: this.message,\n\t\t\tcode: this.code,\n\t\t\terror: this.details,\n\t\t});\n\t}\n\n\t/**\n\t * Gets the default HTTP status message for a given status code.\n\t *\n\t * @param statusCode - The HTTP status code\n\t * @returns The standard HTTP status message or 'Unknown Error' if not found\n\t * @private\n\t */\n\tprivate getDefaultStatusMessage(statusCode: number): string {\n\t\tconst statusMessages: Record<number, string> = {\n\t\t\t400: 'Bad Request',\n\t\t\t401: 'Unauthorized',\n\t\t\t403: 'Forbidden',\n\t\t\t404: 'Not Found',\n\t\t\t405: 'Method Not Allowed',\n\t\t\t406: 'Not Acceptable',\n\t\t\t408: 'Request Timeout',\n\t\t\t409: 'Conflict',\n\t\t\t410: 'Gone',\n\t\t\t422: 'Unprocessable Entity',\n\t\t\t429: 'Too Many Requests',\n\t\t\t500: 'Internal Server Error',\n\t\t\t501: 'Not Implemented',\n\t\t\t502: 'Bad Gateway',\n\t\t\t503: 'Service Unavailable',\n\t\t\t504: 'Gateway Timeout',\n\t\t};\n\t\treturn statusMessages[statusCode] || 'Unknown Error';\n\t}\n\n\t/**\n\t * Serializes the error to a JSON-compatible object.\n\t * Useful for logging and debugging purposes.\n\t *\n\t * @returns Object representation of the error including stack trace\n\t */\n\ttoJSON() {\n\t\treturn {\n\t\t\tname: this.name,\n\t\t\tmessage: this.message,\n\t\t\tstatusCode: this.statusCode,\n\t\t\tstatusMessage: this.statusMessage,\n\t\t\tcode: this.code,\n\t\t\tdetails: this.details,\n\t\t\tstack: this.stack,\n\t\t};\n\t}\n}\n\n// Client Error Classes (4xx)\n\n/**\n * Represents a 400 Bad Request error.\n * Used when the client sends a malformed or invalid request.\n *\n * @extends HttpError\n *\n * @example\n * ```typescript\n * throw new BadRequestError('Invalid JSON', { line: 5, column: 12 });\n * ```\n */\nexport class BadRequestError extends HttpError {\n\tconstructor(message?: string, details?: any) {\n\t\tsuper(400, message, { details });\n\t}\n}\n\n/**\n * Represents a 401 Unauthorized error.\n * Used when authentication is required but not provided or invalid.\n *\n * @extends HttpError\n *\n * @example\n * ```typescript\n * throw new UnauthorizedError('Invalid token');\n * ```\n */\nexport class UnauthorizedError extends HttpError {\n\tconstructor(message?: string, details?: any) {\n\t\tsuper(401, message, { details });\n\t}\n}\n\n/**\n * Represents a 403 Forbidden error.\n * Used when the client is authenticated but lacks permission for the resource.\n *\n * @extends HttpError\n *\n * @example\n * ```typescript\n * throw new ForbiddenError('Insufficient permissions', { required: 'admin' });\n * ```\n */\nexport class ForbiddenError extends HttpError {\n\tconstructor(message?: string, details?: any) {\n\t\tsuper(403, message, { details });\n\t}\n}\n\n/**\n * Represents a 404 Not Found error.\n * Used when the requested resource doesn't exist.\n *\n * @extends HttpError\n *\n * @example\n * ```typescript\n * throw new NotFoundError('User not found', { userId: '123' });\n * ```\n */\nexport class NotFoundError extends HttpError {\n\tconstructor(message?: string, details?: any) {\n\t\tsuper(404, message, { details });\n\t}\n}\n\n/**\n * Represents a 405 Method Not Allowed error.\n * Used when the HTTP method is not supported for the requested resource.\n *\n * @extends HttpError\n *\n * @example\n * ```typescript\n * throw new MethodNotAllowedError('DELETE not supported', ['GET', 'POST', 'PUT']);\n * ```\n */\nexport class MethodNotAllowedError extends HttpError {\n\t/**\n\t * @param message - Optional error message\n\t * @param allowedMethods - Array of allowed HTTP methods for this resource\n\t */\n\tconstructor(message?: string, allowedMethods?: string[]) {\n\t\tsuper(405, message, {\n\t\t\tdetails: allowedMethods ? { allowedMethods } : undefined,\n\t\t});\n\t}\n}\n\n/**\n * Represents a 409 Conflict error.\n * Used when the request conflicts with the current state of the resource.\n *\n * @extends HttpError\n *\n * @example\n * ```typescript\n * throw new ConflictError('Email already exists', { email: 'user@example.com' });\n * ```\n */\nexport class ConflictError extends HttpError {\n\tconstructor(message?: string, details?: any) {\n\t\tsuper(409, message, { details });\n\t}\n}\n\n/**\n * Represents a 422 Unprocessable Entity error.\n * Used when the request is well-formed but contains semantic errors.\n *\n * @extends HttpError\n *\n * @example\n * ```typescript\n * throw new UnprocessableEntityError('Validation failed', {\n * email: 'Invalid format',\n * age: 'Must be 18 or older'\n * });\n * ```\n */\nexport class UnprocessableEntityError extends HttpError {\n\t/**\n\t * @param message - Optional error message\n\t * @param validationErrors - Object containing field-specific validation errors\n\t */\n\tconstructor(message?: string, validationErrors?: any) {\n\t\tsuper(422, message, {\n\t\t\tdetails: validationErrors ? { validationErrors } : undefined,\n\t\t});\n\t}\n}\n\n/**\n * Represents a 429 Too Many Requests error.\n * Used when the client has exceeded rate limits.\n *\n * @extends HttpError\n *\n * @example\n * ```typescript\n * throw new TooManyRequestsError('Rate limit exceeded', 60); // retry after 60 seconds\n * ```\n */\nexport class TooManyRequestsError extends HttpError {\n\t/**\n\t * @param message - Optional error message\n\t * @param retryAfter - Number of seconds the client should wait before retrying\n\t */\n\tconstructor(message?: string, retryAfter?: number) {\n\t\tsuper(429, message, {\n\t\t\tdetails: retryAfter ? { retryAfter } : undefined,\n\t\t});\n\t}\n}\n\n// Server Error Classes (5xx)\n\n/**\n * Represents a 500 Internal Server Error.\n * Used for unexpected server-side errors.\n *\n * @extends HttpError\n *\n * @example\n * ```typescript\n * throw new InternalServerError('Database connection failed');\n * ```\n */\nexport class InternalServerError extends HttpError {\n\tconstructor(message?: string, details?: any) {\n\t\tsuper(500, message, { details });\n\t}\n}\n\n/**\n * Represents a 501 Not Implemented error.\n * Used when the server doesn't support the requested functionality.\n *\n * @extends HttpError\n *\n * @example\n * ```typescript\n * throw new NotImplementedError('WebSocket support not implemented');\n * ```\n */\nexport class NotImplementedError extends HttpError {\n\tconstructor(message?: string, details?: any) {\n\t\tsuper(501, message, { details });\n\t}\n}\n\n/**\n * Represents a 502 Bad Gateway error.\n * Used when the server receives an invalid response from an upstream server.\n *\n * @extends HttpError\n *\n * @example\n * ```typescript\n * throw new BadGatewayError('Upstream server error');\n * ```\n */\nexport class BadGatewayError extends HttpError {\n\tconstructor(message?: string, details?: any) {\n\t\tsuper(502, message, { details });\n\t}\n}\n\n/**\n * Represents a 503 Service Unavailable error.\n * Used when the server is temporarily unable to handle requests.\n *\n * @extends HttpError\n *\n * @example\n * ```typescript\n * throw new ServiceUnavailableError('Maintenance in progress', 300); // retry after 5 minutes\n * ```\n */\nexport class ServiceUnavailableError extends HttpError {\n\t/**\n\t * @param message - Optional error message\n\t * @param retryAfter - Number of seconds the client should wait before retrying\n\t */\n\tconstructor(message?: string, retryAfter?: number) {\n\t\tsuper(503, message, {\n\t\t\tdetails: retryAfter ? { retryAfter } : undefined,\n\t\t});\n\t}\n}\n\n/**\n * Represents a 504 Gateway Timeout error.\n * Used when the server doesn't receive a timely response from an upstream server.\n *\n * @extends HttpError\n *\n * @example\n * ```typescript\n * throw new GatewayTimeoutError('Upstream server timeout');\n * ```\n */\nexport class GatewayTimeoutError extends HttpError {\n\tconstructor(message?: string, details?: any) {\n\t\tsuper(504, message, { details });\n\t}\n}\n\n// Type definitions for different error factory signatures\n\n/** Factory function for standard HTTP errors with optional details */\ntype StandardErrorFactory = (message?: string, details?: any) => HttpError;\n/** Factory function for Method Not Allowed errors with allowed methods */\ntype MethodNotAllowedFactory = (\n\tmessage?: string,\n\tallowedMethods?: string[],\n) => MethodNotAllowedError;\n/** Factory function for errors that include retry-after information */\ntype RetryAfterFactory = (message?: string, retryAfter?: number) => HttpError;\n/** Factory function for validation errors with field-specific errors */\ntype ValidationErrorFactory = (\n\tmessage?: string,\n\tvalidationErrors?: any,\n) => UnprocessableEntityError;\n\n/** Discriminated union for all factory types */\ntype ErrorFactory =\n\t| { type: 'standard'; factory: StandardErrorFactory }\n\t| { type: 'methodNotAllowed'; factory: MethodNotAllowedFactory }\n\t| { type: 'retryAfter'; factory: RetryAfterFactory }\n\t| { type: 'validation'; factory: ValidationErrorFactory };\n\n/** Type-safe error registry mapping status codes to their factory functions */\nconst errorRegistry = {\n\t400: {\n\t\ttype: 'standard',\n\t\tfactory: (m: string, d: any) => new BadRequestError(m, d),\n\t},\n\t401: {\n\t\ttype: 'standard',\n\t\tfactory: (m: string, d: any) => new UnauthorizedError(m, d),\n\t},\n\t403: {\n\t\ttype: 'standard',\n\t\tfactory: (m: string, d: any) => new ForbiddenError(m, d),\n\t},\n\t404: {\n\t\ttype: 'standard',\n\t\tfactory: (m: string, d: any) => new NotFoundError(m, d),\n\t},\n\t405: {\n\t\ttype: 'methodNotAllowed',\n\t\tfactory: (m: string, am: string[]) => new MethodNotAllowedError(m, am),\n\t},\n\t409: {\n\t\ttype: 'standard',\n\t\tfactory: (m: string, d: any) => new ConflictError(m, d),\n\t},\n\t422: {\n\t\ttype: 'validation',\n\t\tfactory: (m: string, ve: any) => new UnprocessableEntityError(m, ve),\n\t},\n\t429: {\n\t\ttype: 'retryAfter',\n\t\tfactory: (m: string, ra: number) => new TooManyRequestsError(m, ra),\n\t},\n\t500: {\n\t\ttype: 'standard',\n\t\tfactory: (m: string, d: any) => new InternalServerError(m, d),\n\t},\n\t501: {\n\t\ttype: 'standard',\n\t\tfactory: (m: string, d: any) => new NotImplementedError(m, d),\n\t},\n\t502: {\n\t\ttype: 'standard',\n\t\tfactory: (m: string, d: any) => new BadGatewayError(m, d),\n\t},\n\t503: {\n\t\ttype: 'retryAfter',\n\t\tfactory: (m: string, ra: number) => new ServiceUnavailableError(m, ra),\n\t},\n\t504: {\n\t\ttype: 'standard',\n\t\tfactory: (m: string, d: any) => new GatewayTimeoutError(m, d),\n\t},\n} as const;\n\n/** Valid status codes that have registered error factories */\ntype ValidStatusCode = keyof typeof errorRegistry;\n\n/** Type-safe options based on status code, ensuring correct parameters for each error type */\ntype ErrorOptions<T extends number> = T extends 405\n\t? { allowedMethods?: string[]; code?: string; cause?: Error }\n\t: T extends 422\n\t\t? { validationErrors?: any; code?: string; cause?: Error }\n\t\t: T extends 429 | 503\n\t\t\t? { retryAfter?: number; code?: string; cause?: Error }\n\t\t\t: { details?: any; code?: string; cause?: Error };\n\n/** Handler functions for each factory type */\nconst factoryHandlers: Record<\n\tErrorFactory['type'],\n\t(entry: any, message?: string, options?: any) => HttpError\n> = {\n\tstandard: (entry, message, options) =>\n\t\tentry.factory(message, options?.details),\n\tmethodNotAllowed: (entry, message, options) =>\n\t\tentry.factory(message, options?.allowedMethods),\n\tretryAfter: (entry, message, options) =>\n\t\tentry.factory(message, options?.retryAfter),\n\tvalidation: (entry, message, options) =>\n\t\tentry.factory(message, options?.validationErrors),\n};\n\n/**\n * Creates an HTTP error with type-safe options based on the status code.\n * Provides IntelliSense support for status-code-specific options.\n *\n * @overload For known status codes with specific options\n * @param statusCode - A valid HTTP status code from the registry\n * @param message - Optional error message\n * @param options - Status-code-specific options\n * @returns The appropriate HttpError subclass\n *\n * @example\n * ```typescript\n * // TypeScript knows allowedMethods is valid for 405\n * createHttpError(405, 'Method not allowed', { allowedMethods: ['GET', 'POST'] });\n *\n * // TypeScript knows retryAfter is valid for 429\n * createHttpError(429, 'Rate limited', { retryAfter: 60 });\n * ```\n */\nexport function createHttpError<T extends ValidStatusCode>(\n\tstatusCode: T,\n\tmessage?: string,\n\toptions?: ErrorOptions<T>,\n): HttpError;\nexport function createHttpError(\n\tstatusCode: number,\n\tmessage?: string,\n\toptions?: HttpErrorOptions,\n): HttpError;\nexport function createHttpError(\n\tstatusCode: number,\n\tmessage?: string,\n\toptions?: any,\n): HttpError {\n\tconst entry = errorRegistry[statusCode as ValidStatusCode];\n\n\tif (entry) {\n\t\tconst handler = factoryHandlers[entry.type];\n\t\treturn handler(entry, message, options);\n\t}\n\n\t// Fallback to generic HttpError for unknown status codes\n\treturn new HttpError(statusCode, message, options);\n}\n\n/**\n * Type-safe error creation utilities with descriptive method names.\n * Provides a fluent API for creating specific HTTP errors.\n *\n * @example\n * ```typescript\n * createError.notFound('User not found');\n * createError.badRequest('Invalid input', { field: 'email' });\n * createError.methodNotAllowed('DELETE not supported', ['GET', 'POST']);\n * ```\n */\nexport const createError = {\n\tbadRequest: (message?: string, details?: any) =>\n\t\tnew BadRequestError(message, details),\n\n\tunauthorized: (message?: string, details?: any) =>\n\t\tnew UnauthorizedError(message, details),\n\n\tforbidden: (message?: string, details?: any) =>\n\t\tnew ForbiddenError(message, details),\n\n\tnotFound: (message?: string, details?: any) =>\n\t\tnew NotFoundError(message, details),\n\n\tmethodNotAllowed: (message?: string, allowedMethods?: string[]) =>\n\t\tnew MethodNotAllowedError(message, allowedMethods),\n\n\tconflict: (message?: string, details?: any) =>\n\t\tnew ConflictError(message, details),\n\n\tunprocessableEntity: (message?: string, validationErrors?: any) =>\n\t\tnew UnprocessableEntityError(message, validationErrors),\n\n\ttooManyRequests: (message?: string, retryAfter?: number) =>\n\t\tnew TooManyRequestsError(message, retryAfter),\n\n\tinternalServerError: (message?: string, details?: any) =>\n\t\tnew InternalServerError(message, details),\n\n\tnotImplemented: (message?: string, details?: any) =>\n\t\tnew NotImplementedError(message, details),\n\n\tbadGateway: (message?: string, details?: any) =>\n\t\tnew BadGatewayError(message, details),\n\n\tserviceUnavailable: (message?: string, retryAfter?: number) =>\n\t\tnew ServiceUnavailableError(message, retryAfter),\n\n\tgatewayTimeout: (message?: string, details?: any) =>\n\t\tnew GatewayTimeoutError(message, details),\n} as const;\n\n// Type guards\n\n/**\n * Type guard to check if an error is an HttpError.\n * Works with both instanceof checks and duck typing.\n *\n * @param error - The error to check\n * @returns True if the error is an HttpError\n *\n * @example\n * ```typescript\n * try {\n * // some code\n * } catch (error) {\n * if (isHttpError(error)) {\n * console.log(`HTTP ${error.statusCode}: ${error.message}`);\n * }\n * }\n * ```\n */\nexport function isHttpError(error: unknown): error is HttpError {\n\treturn (\n\t\terror instanceof HttpError ||\n\t\t(error !== null &&\n\t\t\ttypeof error === 'object' &&\n\t\t\t'isHttpError' in error &&\n\t\t\terror.isHttpError === true)\n\t);\n}\n\n/**\n * Type guard to check if an error is a client error (4xx status code).\n *\n * @param error - The error to check\n * @returns True if the error is an HttpError with a 4xx status code\n *\n * @example\n * ```typescript\n * if (isClientError(error)) {\n * // Log client error metrics\n * }\n * ```\n */\nexport function isClientError(error: unknown): error is HttpError {\n\treturn (\n\t\tisHttpError(error) && error.statusCode >= 400 && error.statusCode < 500\n\t);\n}\n\n/**\n * Type guard to check if an error is a server error (5xx status code).\n *\n * @param error - The error to check\n * @returns True if the error is an HttpError with a 5xx status code\n *\n * @example\n * ```typescript\n * if (isServerError(error)) {\n * // Trigger alerts for server errors\n * }\n * ```\n */\nexport function isServerError(error: unknown): error is HttpError {\n\treturn (\n\t\tisHttpError(error) && error.statusCode >= 500 && error.statusCode < 600\n\t);\n}\n\n// Utility functions\n\n/**\n * Wraps an unknown error into an HttpError.\n * If the error is already an HttpError, returns it unchanged.\n *\n * @param error - The error to wrap\n * @param statusCode - The HTTP status code to use (defaults to 500)\n * @param message - Optional message to override the original error message\n * @returns An HttpError instance\n *\n * @example\n * ```typescript\n * try {\n * await someOperation();\n * } catch (error) {\n * throw wrapError(error, 503, 'Service temporarily unavailable');\n * }\n * ```\n */\nexport function wrapError(\n\terror: unknown,\n\tstatusCode = 500,\n\tmessage?: string,\n): HttpError {\n\tif (isHttpError(error)) {\n\t\treturn error;\n\t}\n\n\tif (error instanceof HttpError) {\n\t\treturn error;\n\t}\n\n\treturn new HttpError(statusCode, message || 'An unknown error occurred', {\n\t\tdetails: { originalError: error },\n\t});\n}\n\n// Types for better TypeScript support\n\n/**\n * Options for creating an HttpError.\n */\nexport interface HttpErrorOptions {\n\tstatusMessage?: string;\n\tdetails?: any;\n\tcode?: string;\n\tcause?: Error;\n}\n\n/**\n * Constructor type for HttpError classes.\n * Useful for factory patterns and dependency injection.\n */\nexport type HttpErrorConstructor = new (\n\tmessage?: string,\n\toptions?: HttpErrorOptions,\n) => HttpError;\n\n/**\n * HTTP status code enum for type-safe status code usage.\n * Includes common 2xx, 3xx, 4xx, and 5xx status codes.\n */\nexport enum HttpStatusCode {\n\t// 2xx Success\n\tOK = 200,\n\tCREATED = 201,\n\tACCEPTED = 202,\n\tNO_CONTENT = 204,\n\n\t// 3xx Redirection\n\tMOVED_PERMANENTLY = 301,\n\tFOUND = 302,\n\tNOT_MODIFIED = 304,\n\n\t// 4xx Client Error\n\tBAD_REQUEST = 400,\n\tUNAUTHORIZED = 401,\n\tFORBIDDEN = 403,\n\tNOT_FOUND = 404,\n\tMETHOD_NOT_ALLOWED = 405,\n\tNOT_ACCEPTABLE = 406,\n\tREQUEST_TIMEOUT = 408,\n\tCONFLICT = 409,\n\tGONE = 410,\n\tUNPROCESSABLE_ENTITY = 422,\n\tTOO_MANY_REQUESTS = 429,\n\n\t// 5xx Server Error\n\tINTERNAL_SERVER_ERROR = 500,\n\tNOT_IMPLEMENTED = 501,\n\tBAD_GATEWAY = 502,\n\tSERVICE_UNAVAILABLE = 503,\n\tGATEWAY_TIMEOUT = 504,\n}\n\n/**\n * Namespace containing all HTTP error classes.\n * Useful for importing all error types at once.\n *\n * @example\n * ```typescript\n * import { HttpErrors } from '@geekmidas/errors';\n * throw new HttpErrors.NotFoundError('Resource not found');\n * ```\n */\nexport const HttpErrors = {\n\tHttpError,\n\tBadRequestError,\n\tUnauthorizedError,\n\tForbiddenError,\n\tNotFoundError,\n\tMethodNotAllowedError,\n\tConflictError,\n\tUnprocessableEntityError,\n\tTooManyRequestsError,\n\tInternalServerError,\n\tNotImplementedError,\n\tBadGatewayError,\n\tServiceUnavailableError,\n\tGatewayTimeoutError,\n};\n\n// Usage examples:\n/*\n// Basic usage\nthrow new NotFoundError('User not found');\nthrow new BadRequestError('Invalid email format', { field: 'email' });\n\n// With validation errors\nthrow new UnprocessableEntityError('Validation failed', {\n email: 'Invalid email format',\n password: 'Password must be at least 8 characters',\n});\n\n// Type-safe factory function with IntelliSense support\nthrow createHttpError(405, 'Method not allowed', { \n allowedMethods: ['GET', 'POST'] // TypeScript knows this is the correct option!\n});\n\nthrow createHttpError(429, 'Too many requests', { \n retryAfter: 60 // TypeScript knows this needs retryAfter, not details!\n});\n\nthrow createHttpError(422, 'Validation failed', {\n validationErrors: { // TypeScript knows this is for validation errors\n email: 'Invalid format',\n age: 'Must be 18+'\n }\n});\n\n// Using the type-safe createError object\nthrow createError.methodNotAllowed('DELETE not supported', ['GET', 'POST']);\nthrow createError.tooManyRequests('Rate limit exceeded', 60);\nthrow createError.unprocessableEntity('Invalid input', {\n field: 'email',\n message: 'Invalid format'\n});\n\n// TypeScript will show errors for incorrect usage:\n// throw createHttpError(404, 'Not found', { retryAfter: 60 }); // ❌ Type error!\n// throw createError.notFound('User not found', 60); // ❌ Type error!\n\n// Wrapping unknown errors\ntry {\n await someAsyncOperation();\n} catch (error) {\n throw wrapError(error, 500, 'Failed to process request');\n}\n\n// In Express middleware\napp.use(expressErrorHandler);\n\n// Type checking\nif (isClientError(error)) {\n console.log('Client made a bad request');\n}\n*/\n"],"mappings":";;;;;;;;;;;;;;;AAeA,IAAa,YAAb,cAA+B,MAAM;;CAEpC,AAAgB;;CAEhB,AAAgB;;CAEhB,AAAgB,cAAc;;CAE9B,AAAgB;;CAEhB,AAAgB;;;;;;;;;;;;CAahB,YACCA,YACAC,SACAC,SAMC;AACD,QAAM,WAAW,SAAS,iBAAiB,aAAa;AACxD,OAAK,OAAO,KAAK,YAAY;AAC7B,OAAK,aAAa;AAClB,OAAK,gBACJ,SAAS,iBAAiB,KAAK,wBAAwB,WAAW;AACnE,OAAK,UAAU,SAAS;AACxB,OAAK,OAAO,SAAS;AAGrB,MAAI,SAAS,MACZ,MAAK,QAAQ,QAAQ;AAGtB,QAAM,kBAAkB,MAAM,KAAK,YAAY;CAC/C;;;;;;;CAQD,IAAI,OAAO;AACV,SAAO,KAAK,UAAU;GACrB,SAAS,KAAK;GACd,MAAM,KAAK;GACX,OAAO,KAAK;EACZ,EAAC;CACF;;;;;;;;CASD,AAAQ,wBAAwBF,YAA4B;EAC3D,MAAMG,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,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"}
package/dist/index.d.cts CHANGED
@@ -66,9 +66,9 @@ declare class HttpError extends Error {
66
66
  message: string;
67
67
  statusCode: number;
68
68
  statusMessage: string;
69
- code: string;
69
+ code: string | undefined;
70
70
  details: any;
71
- stack: string;
71
+ stack: string | undefined;
72
72
  };
73
73
  }
74
74
  /**
@@ -0,0 +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,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AIJ;;;;6CAIA;;;;6CAIA;;;;iDAII;;;;6CAIJ;;;;KAKxB,eAAA,gBAA+B;;KAG/B,iCAAiC;;;UACiB;IACpD;;;UACkD;IACjD;;;UAC+C;;;;UACN;;;;;;;;;;;;;;;;;;;;;iBAoC7B,0BAA0B,6BAC7B,+BAEF,aAAa,KACrB;iBACa,eAAA,iDAGL,mBACR;;;;;;;;;;;;cA4BU;4DACgC;8DAGE;2DAGH;0DAGD;8EAGoB;0DAGpB;8EAGoB;uEAGP;qEAGF;gEAGL;4DAGJ;0EAGc;gEAGV;;;;;;;;;;;;;;;;;;;;iBAwBjC,WAAA,2BAAsC;;;;;;;;;;;;;;iBAuBtC,aAAA,2BAAwC;;;;;;;;;;;;;;iBAmBxC,aAAA,2BAAwC;;;;;;;;;;;;;;;;;;;iBA0BxC,SAAA,yDAIb;;;;UAmBc,gBAAA;;;;UAIR;;;;;;KAOG,oBAAA,oCAED,qBACN;;;;;aAMO,cAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;cA2CC;oBAeZ"}
package/dist/index.d.mts CHANGED
@@ -66,9 +66,9 @@ declare class HttpError extends Error {
66
66
  message: string;
67
67
  statusCode: number;
68
68
  statusMessage: string;
69
- code: string;
69
+ code: string | undefined;
70
70
  details: any;
71
- stack: string;
71
+ stack: string | undefined;
72
72
  };
73
73
  }
74
74
  /**
@@ -0,0 +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;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,IAA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SAA4B,SAAS;;;;;;;;;;;;;;cAiBrC,eAAA,SAAwB,SAAS;;;;;;;;;;;;;;cAiBjC,uBAAA,SAAgC,SAAS;;;;;;;;;;;;;;;;;;cAuBzC,mBAAA,SAA4B,SAAS;;;;cA+B5C;;;6CAGuB;;;;6CAIA;;;;6CAIA;;;;6CAIA;;;;mDAIM;;;;6CAIN;;;;8CAIC;;;;iDAIG;;;;6CAIJ;;;;6CAIA;;;;6CAIA;;;;iDAII;;;;6CAIJ;;;;KAKxB,eAAA,gBAA+B;;KAG/B,iCAAiC;;;UACiB;IACpD;;;UACkD;IACjD;;;UAC+C;;;;UACN;;;;;;;;;;;;;;;;;;;;;iBAoC7B,0BAA0B,6BAC7B,+BAEF,aAAa,KACrB;iBACa,eAAA,iDAGL,mBACR;;;;;;;;;;;;cA4BU;4DACgC;8DAGE;2DAGH;0DAGD;8EAGoB;0DAGpB;8EAGoB;uEAGP;qEAGF;gEAGL;4DAGJ;0EAGc;gEAGV;;;;;;;;;;;;;;;;;;;;iBAwBjC,WAAA,2BAAsC;;;;;;;;;;;;;;iBAuBtC,aAAA,2BAAwC;;;;;;;;;;;;;;iBAmBxC,aAAA,2BAAwC;;;;;;;;;;;;;;;;;;;iBA0BxC,SAAA,yDAIb;;;;UAmBc,gBAAA;;;;UAIR;;;;;;KAOG,oBAAA,oCAED,qBACN;;;;;aAMO,cAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;cA2CC;oBAeZ"}
@@ -1 +1 @@
1
- {"version":3,"file":"index.mjs","names":["statusCode: number","message?: string","options?: {\n statusMessage?: string;\n details?: any;\n code?: string;\n cause?: Error;\n }","statusMessages: Record<number, string>","details?: any","allowedMethods?: string[]","validationErrors?: any","retryAfter?: number","m: string","d: any","am: string[]","ve: any","ra: number","factoryHandlers: Record<\n ErrorFactory['type'],\n (entry: any, message?: string, options?: any) => HttpError\n>","options?: any","error: unknown"],"sources":["../src/index.ts"],"sourcesContent":["// http-errors.ts - Core HTTP Error Classes and Types\n\n/**\n * Base HTTP Error class that extends the native Error.\n * Provides a foundation for all HTTP-specific errors with status codes and structured error responses.\n *\n * @extends Error\n *\n * @example\n * ```typescript\n * throw new HttpError(400, 'Bad Request', {\n * details: { field: 'email', message: 'Invalid format' }\n * });\n * ```\n */\nexport class HttpError extends Error {\n /** The HTTP status code (e.g., 400, 404, 500) */\n public readonly statusCode: number;\n /** The standard HTTP status message (e.g., 'Bad Request', 'Not Found') */\n public readonly statusMessage: string;\n /** Type discriminator for runtime type checking */\n public readonly isHttpError = true;\n /** Additional error details for debugging or client information */\n public readonly details?: any;\n /** Application-specific error code for client-side handling */\n public readonly code?: string;\n\n /**\n * Creates a new HttpError instance.\n *\n * @param statusCode - The HTTP status code\n * @param message - Optional error message for the client\n * @param options - Optional configuration object\n * @param options.statusMessage - Override the default status message\n * @param options.details - Additional error details or context\n * @param options.code - Application-specific error code\n * @param options.cause - The underlying error that caused this error (ES2022)\n */\n constructor(\n statusCode: number,\n message?: string,\n options?: {\n statusMessage?: string;\n details?: any;\n code?: string;\n cause?: Error;\n },\n ) {\n super(message || options?.statusMessage || 'HTTP Error');\n this.name = this.constructor.name;\n this.statusCode = statusCode;\n this.statusMessage =\n options?.statusMessage || this.getDefaultStatusMessage(statusCode);\n this.details = options?.details;\n this.code = options?.code;\n\n // Set cause if provided (ES2022 feature)\n if (options?.cause) {\n this.cause = options.cause;\n }\n // @ts-ignore\n // Maintains proper stack trace for where our error was thrown\n Error.captureStackTrace(this, this.constructor);\n }\n\n /**\n * Gets the error response body as a JSON string.\n * Used for sending the error response to clients.\n *\n * @returns JSON string containing message, code, and error details\n */\n get body() {\n return JSON.stringify({\n message: this.message,\n code: this.code,\n error: this.details,\n });\n }\n\n /**\n * Gets the default HTTP status message for a given status code.\n *\n * @param statusCode - The HTTP status code\n * @returns The standard HTTP status message or 'Unknown Error' if not found\n * @private\n */\n private getDefaultStatusMessage(statusCode: number): string {\n const statusMessages: Record<number, string> = {\n 400: 'Bad Request',\n 401: 'Unauthorized',\n 403: 'Forbidden',\n 404: 'Not Found',\n 405: 'Method Not Allowed',\n 406: 'Not Acceptable',\n 408: 'Request Timeout',\n 409: 'Conflict',\n 410: 'Gone',\n 422: 'Unprocessable Entity',\n 429: 'Too Many Requests',\n 500: 'Internal Server Error',\n 501: 'Not Implemented',\n 502: 'Bad Gateway',\n 503: 'Service Unavailable',\n 504: 'Gateway Timeout',\n };\n return statusMessages[statusCode] || 'Unknown Error';\n }\n\n /**\n * Serializes the error to a JSON-compatible object.\n * Useful for logging and debugging purposes.\n *\n * @returns Object representation of the error including stack trace\n */\n toJSON() {\n return {\n name: this.name,\n message: this.message,\n statusCode: this.statusCode,\n statusMessage: this.statusMessage,\n code: this.code,\n details: this.details,\n stack: this.stack,\n };\n }\n}\n\n// Client Error Classes (4xx)\n\n/**\n * Represents a 400 Bad Request error.\n * Used when the client sends a malformed or invalid request.\n *\n * @extends HttpError\n *\n * @example\n * ```typescript\n * throw new BadRequestError('Invalid JSON', { line: 5, column: 12 });\n * ```\n */\nexport class BadRequestError extends HttpError {\n constructor(message?: string, details?: any) {\n super(400, message, { details });\n }\n}\n\n/**\n * Represents a 401 Unauthorized error.\n * Used when authentication is required but not provided or invalid.\n *\n * @extends HttpError\n *\n * @example\n * ```typescript\n * throw new UnauthorizedError('Invalid token');\n * ```\n */\nexport class UnauthorizedError extends HttpError {\n constructor(message?: string, details?: any) {\n super(401, message, { details });\n }\n}\n\n/**\n * Represents a 403 Forbidden error.\n * Used when the client is authenticated but lacks permission for the resource.\n *\n * @extends HttpError\n *\n * @example\n * ```typescript\n * throw new ForbiddenError('Insufficient permissions', { required: 'admin' });\n * ```\n */\nexport class ForbiddenError extends HttpError {\n constructor(message?: string, details?: any) {\n super(403, message, { details });\n }\n}\n\n/**\n * Represents a 404 Not Found error.\n * Used when the requested resource doesn't exist.\n *\n * @extends HttpError\n *\n * @example\n * ```typescript\n * throw new NotFoundError('User not found', { userId: '123' });\n * ```\n */\nexport class NotFoundError extends HttpError {\n constructor(message?: string, details?: any) {\n super(404, message, { details });\n }\n}\n\n/**\n * Represents a 405 Method Not Allowed error.\n * Used when the HTTP method is not supported for the requested resource.\n *\n * @extends HttpError\n *\n * @example\n * ```typescript\n * throw new MethodNotAllowedError('DELETE not supported', ['GET', 'POST', 'PUT']);\n * ```\n */\nexport class MethodNotAllowedError extends HttpError {\n /**\n * @param message - Optional error message\n * @param allowedMethods - Array of allowed HTTP methods for this resource\n */\n constructor(message?: string, allowedMethods?: string[]) {\n super(405, message, {\n details: allowedMethods ? { allowedMethods } : undefined,\n });\n }\n}\n\n/**\n * Represents a 409 Conflict error.\n * Used when the request conflicts with the current state of the resource.\n *\n * @extends HttpError\n *\n * @example\n * ```typescript\n * throw new ConflictError('Email already exists', { email: 'user@example.com' });\n * ```\n */\nexport class ConflictError extends HttpError {\n constructor(message?: string, details?: any) {\n super(409, message, { details });\n }\n}\n\n/**\n * Represents a 422 Unprocessable Entity error.\n * Used when the request is well-formed but contains semantic errors.\n *\n * @extends HttpError\n *\n * @example\n * ```typescript\n * throw new UnprocessableEntityError('Validation failed', {\n * email: 'Invalid format',\n * age: 'Must be 18 or older'\n * });\n * ```\n */\nexport class UnprocessableEntityError extends HttpError {\n /**\n * @param message - Optional error message\n * @param validationErrors - Object containing field-specific validation errors\n */\n constructor(message?: string, validationErrors?: any) {\n super(422, message, {\n details: validationErrors ? { validationErrors } : undefined,\n });\n }\n}\n\n/**\n * Represents a 429 Too Many Requests error.\n * Used when the client has exceeded rate limits.\n *\n * @extends HttpError\n *\n * @example\n * ```typescript\n * throw new TooManyRequestsError('Rate limit exceeded', 60); // retry after 60 seconds\n * ```\n */\nexport class TooManyRequestsError extends HttpError {\n /**\n * @param message - Optional error message\n * @param retryAfter - Number of seconds the client should wait before retrying\n */\n constructor(message?: string, retryAfter?: number) {\n super(429, message, {\n details: retryAfter ? { retryAfter } : undefined,\n });\n }\n}\n\n// Server Error Classes (5xx)\n\n/**\n * Represents a 500 Internal Server Error.\n * Used for unexpected server-side errors.\n *\n * @extends HttpError\n *\n * @example\n * ```typescript\n * throw new InternalServerError('Database connection failed');\n * ```\n */\nexport class InternalServerError extends HttpError {\n constructor(message?: string, details?: any) {\n super(500, message, { details });\n }\n}\n\n/**\n * Represents a 501 Not Implemented error.\n * Used when the server doesn't support the requested functionality.\n *\n * @extends HttpError\n *\n * @example\n * ```typescript\n * throw new NotImplementedError('WebSocket support not implemented');\n * ```\n */\nexport class NotImplementedError extends HttpError {\n constructor(message?: string, details?: any) {\n super(501, message, { details });\n }\n}\n\n/**\n * Represents a 502 Bad Gateway error.\n * Used when the server receives an invalid response from an upstream server.\n *\n * @extends HttpError\n *\n * @example\n * ```typescript\n * throw new BadGatewayError('Upstream server error');\n * ```\n */\nexport class BadGatewayError extends HttpError {\n constructor(message?: string, details?: any) {\n super(502, message, { details });\n }\n}\n\n/**\n * Represents a 503 Service Unavailable error.\n * Used when the server is temporarily unable to handle requests.\n *\n * @extends HttpError\n *\n * @example\n * ```typescript\n * throw new ServiceUnavailableError('Maintenance in progress', 300); // retry after 5 minutes\n * ```\n */\nexport class ServiceUnavailableError extends HttpError {\n /**\n * @param message - Optional error message\n * @param retryAfter - Number of seconds the client should wait before retrying\n */\n constructor(message?: string, retryAfter?: number) {\n super(503, message, {\n details: retryAfter ? { retryAfter } : undefined,\n });\n }\n}\n\n/**\n * Represents a 504 Gateway Timeout error.\n * Used when the server doesn't receive a timely response from an upstream server.\n *\n * @extends HttpError\n *\n * @example\n * ```typescript\n * throw new GatewayTimeoutError('Upstream server timeout');\n * ```\n */\nexport class GatewayTimeoutError extends HttpError {\n constructor(message?: string, details?: any) {\n super(504, message, { details });\n }\n}\n\n// Type definitions for different error factory signatures\n\n/** Factory function for standard HTTP errors with optional details */\ntype StandardErrorFactory = (message?: string, details?: any) => HttpError;\n/** Factory function for Method Not Allowed errors with allowed methods */\ntype MethodNotAllowedFactory = (\n message?: string,\n allowedMethods?: string[],\n) => MethodNotAllowedError;\n/** Factory function for errors that include retry-after information */\ntype RetryAfterFactory = (message?: string, retryAfter?: number) => HttpError;\n/** Factory function for validation errors with field-specific errors */\ntype ValidationErrorFactory = (\n message?: string,\n validationErrors?: any,\n) => UnprocessableEntityError;\n\n/** Discriminated union for all factory types */\ntype ErrorFactory =\n | { type: 'standard'; factory: StandardErrorFactory }\n | { type: 'methodNotAllowed'; factory: MethodNotAllowedFactory }\n | { type: 'retryAfter'; factory: RetryAfterFactory }\n | { type: 'validation'; factory: ValidationErrorFactory };\n\n/** Type-safe error registry mapping status codes to their factory functions */\nconst errorRegistry = {\n 400: {\n type: 'standard',\n factory: (m: string, d: any) => new BadRequestError(m, d),\n },\n 401: {\n type: 'standard',\n factory: (m: string, d: any) => new UnauthorizedError(m, d),\n },\n 403: {\n type: 'standard',\n factory: (m: string, d: any) => new ForbiddenError(m, d),\n },\n 404: {\n type: 'standard',\n factory: (m: string, d: any) => new NotFoundError(m, d),\n },\n 405: {\n type: 'methodNotAllowed',\n factory: (m: string, am: string[]) => new MethodNotAllowedError(m, am),\n },\n 409: {\n type: 'standard',\n factory: (m: string, d: any) => new ConflictError(m, d),\n },\n 422: {\n type: 'validation',\n factory: (m: string, ve: any) => new UnprocessableEntityError(m, ve),\n },\n 429: {\n type: 'retryAfter',\n factory: (m: string, ra: number) => new TooManyRequestsError(m, ra),\n },\n 500: {\n type: 'standard',\n factory: (m: string, d: any) => new InternalServerError(m, d),\n },\n 501: {\n type: 'standard',\n factory: (m: string, d: any) => new NotImplementedError(m, d),\n },\n 502: {\n type: 'standard',\n factory: (m: string, d: any) => new BadGatewayError(m, d),\n },\n 503: {\n type: 'retryAfter',\n factory: (m: string, ra: number) => new ServiceUnavailableError(m, ra),\n },\n 504: {\n type: 'standard',\n factory: (m: string, d: any) => new GatewayTimeoutError(m, d),\n },\n} as const;\n\n/** Valid status codes that have registered error factories */\ntype ValidStatusCode = keyof typeof errorRegistry;\n\n/** Type-safe options based on status code, ensuring correct parameters for each error type */\ntype ErrorOptions<T extends number> = T extends 405\n ? { allowedMethods?: string[]; code?: string; cause?: Error }\n : T extends 422\n ? { validationErrors?: any; code?: string; cause?: Error }\n : T extends 429 | 503\n ? { retryAfter?: number; code?: string; cause?: Error }\n : { details?: any; code?: string; cause?: Error };\n\n/** Handler functions for each factory type */\nconst factoryHandlers: Record<\n ErrorFactory['type'],\n (entry: any, message?: string, options?: any) => HttpError\n> = {\n standard: (entry, message, options) =>\n entry.factory(message, options?.details),\n methodNotAllowed: (entry, message, options) =>\n entry.factory(message, options?.allowedMethods),\n retryAfter: (entry, message, options) =>\n entry.factory(message, options?.retryAfter),\n validation: (entry, message, options) =>\n entry.factory(message, options?.validationErrors),\n};\n\n/**\n * Creates an HTTP error with type-safe options based on the status code.\n * Provides IntelliSense support for status-code-specific options.\n *\n * @overload For known status codes with specific options\n * @param statusCode - A valid HTTP status code from the registry\n * @param message - Optional error message\n * @param options - Status-code-specific options\n * @returns The appropriate HttpError subclass\n *\n * @example\n * ```typescript\n * // TypeScript knows allowedMethods is valid for 405\n * createHttpError(405, 'Method not allowed', { allowedMethods: ['GET', 'POST'] });\n *\n * // TypeScript knows retryAfter is valid for 429\n * createHttpError(429, 'Rate limited', { retryAfter: 60 });\n * ```\n */\nexport function createHttpError<T extends ValidStatusCode>(\n statusCode: T,\n message?: string,\n options?: ErrorOptions<T>,\n): HttpError;\nexport function createHttpError(\n statusCode: number,\n message?: string,\n options?: HttpErrorOptions,\n): HttpError;\nexport function createHttpError(\n statusCode: number,\n message?: string,\n options?: any,\n): HttpError {\n const entry = errorRegistry[statusCode as ValidStatusCode];\n\n if (entry) {\n const handler = factoryHandlers[entry.type];\n return handler(entry, message, options);\n }\n\n // Fallback to generic HttpError for unknown status codes\n return new HttpError(statusCode, message, options);\n}\n\n/**\n * Type-safe error creation utilities with descriptive method names.\n * Provides a fluent API for creating specific HTTP errors.\n *\n * @example\n * ```typescript\n * createError.notFound('User not found');\n * createError.badRequest('Invalid input', { field: 'email' });\n * createError.methodNotAllowed('DELETE not supported', ['GET', 'POST']);\n * ```\n */\nexport const createError = {\n badRequest: (message?: string, details?: any) =>\n new BadRequestError(message, details),\n\n unauthorized: (message?: string, details?: any) =>\n new UnauthorizedError(message, details),\n\n forbidden: (message?: string, details?: any) =>\n new ForbiddenError(message, details),\n\n notFound: (message?: string, details?: any) =>\n new NotFoundError(message, details),\n\n methodNotAllowed: (message?: string, allowedMethods?: string[]) =>\n new MethodNotAllowedError(message, allowedMethods),\n\n conflict: (message?: string, details?: any) =>\n new ConflictError(message, details),\n\n unprocessableEntity: (message?: string, validationErrors?: any) =>\n new UnprocessableEntityError(message, validationErrors),\n\n tooManyRequests: (message?: string, retryAfter?: number) =>\n new TooManyRequestsError(message, retryAfter),\n\n internalServerError: (message?: string, details?: any) =>\n new InternalServerError(message, details),\n\n notImplemented: (message?: string, details?: any) =>\n new NotImplementedError(message, details),\n\n badGateway: (message?: string, details?: any) =>\n new BadGatewayError(message, details),\n\n serviceUnavailable: (message?: string, retryAfter?: number) =>\n new ServiceUnavailableError(message, retryAfter),\n\n gatewayTimeout: (message?: string, details?: any) =>\n new GatewayTimeoutError(message, details),\n} as const;\n\n// Type guards\n\n/**\n * Type guard to check if an error is an HttpError.\n * Works with both instanceof checks and duck typing.\n *\n * @param error - The error to check\n * @returns True if the error is an HttpError\n *\n * @example\n * ```typescript\n * try {\n * // some code\n * } catch (error) {\n * if (isHttpError(error)) {\n * console.log(`HTTP ${error.statusCode}: ${error.message}`);\n * }\n * }\n * ```\n */\nexport function isHttpError(error: unknown): error is HttpError {\n return (\n error instanceof HttpError ||\n (error !== null &&\n typeof error === 'object' &&\n 'isHttpError' in error &&\n error.isHttpError === true)\n );\n}\n\n/**\n * Type guard to check if an error is a client error (4xx status code).\n *\n * @param error - The error to check\n * @returns True if the error is an HttpError with a 4xx status code\n *\n * @example\n * ```typescript\n * if (isClientError(error)) {\n * // Log client error metrics\n * }\n * ```\n */\nexport function isClientError(error: unknown): error is HttpError {\n return (\n isHttpError(error) && error.statusCode >= 400 && error.statusCode < 500\n );\n}\n\n/**\n * Type guard to check if an error is a server error (5xx status code).\n *\n * @param error - The error to check\n * @returns True if the error is an HttpError with a 5xx status code\n *\n * @example\n * ```typescript\n * if (isServerError(error)) {\n * // Trigger alerts for server errors\n * }\n * ```\n */\nexport function isServerError(error: unknown): error is HttpError {\n return (\n isHttpError(error) && error.statusCode >= 500 && error.statusCode < 600\n );\n}\n\n// Utility functions\n\n/**\n * Wraps an unknown error into an HttpError.\n * If the error is already an HttpError, returns it unchanged.\n *\n * @param error - The error to wrap\n * @param statusCode - The HTTP status code to use (defaults to 500)\n * @param message - Optional message to override the original error message\n * @returns An HttpError instance\n *\n * @example\n * ```typescript\n * try {\n * await someOperation();\n * } catch (error) {\n * throw wrapError(error, 503, 'Service temporarily unavailable');\n * }\n * ```\n */\nexport function wrapError(\n error: unknown,\n statusCode = 500,\n message?: string,\n): HttpError {\n if (isHttpError(error)) {\n return error;\n }\n\n if (error instanceof HttpError) {\n return error;\n }\n\n return new HttpError(statusCode, message || 'An unknown error occurred', {\n details: { originalError: error },\n });\n}\n\n// Types for better TypeScript support\n\n/**\n * Options for creating an HttpError.\n */\nexport interface HttpErrorOptions {\n statusMessage?: string;\n details?: any;\n code?: string;\n cause?: Error;\n}\n\n/**\n * Constructor type for HttpError classes.\n * Useful for factory patterns and dependency injection.\n */\nexport type HttpErrorConstructor = new (\n message?: string,\n options?: HttpErrorOptions,\n) => HttpError;\n\n/**\n * HTTP status code enum for type-safe status code usage.\n * Includes common 2xx, 3xx, 4xx, and 5xx status codes.\n */\nexport enum HttpStatusCode {\n // 2xx Success\n OK = 200,\n CREATED = 201,\n ACCEPTED = 202,\n NO_CONTENT = 204,\n\n // 3xx Redirection\n MOVED_PERMANENTLY = 301,\n FOUND = 302,\n NOT_MODIFIED = 304,\n\n // 4xx Client Error\n BAD_REQUEST = 400,\n UNAUTHORIZED = 401,\n FORBIDDEN = 403,\n NOT_FOUND = 404,\n METHOD_NOT_ALLOWED = 405,\n NOT_ACCEPTABLE = 406,\n REQUEST_TIMEOUT = 408,\n CONFLICT = 409,\n GONE = 410,\n UNPROCESSABLE_ENTITY = 422,\n TOO_MANY_REQUESTS = 429,\n\n // 5xx Server Error\n INTERNAL_SERVER_ERROR = 500,\n NOT_IMPLEMENTED = 501,\n BAD_GATEWAY = 502,\n SERVICE_UNAVAILABLE = 503,\n GATEWAY_TIMEOUT = 504,\n}\n\n/**\n * Namespace containing all HTTP error classes.\n * Useful for importing all error types at once.\n *\n * @example\n * ```typescript\n * import { HttpErrors } from '@geekmidas/errors';\n * throw new HttpErrors.NotFoundError('Resource not found');\n * ```\n */\nexport const HttpErrors = {\n HttpError,\n BadRequestError,\n UnauthorizedError,\n ForbiddenError,\n NotFoundError,\n MethodNotAllowedError,\n ConflictError,\n UnprocessableEntityError,\n TooManyRequestsError,\n InternalServerError,\n NotImplementedError,\n BadGatewayError,\n ServiceUnavailableError,\n GatewayTimeoutError,\n};\n\n// Usage examples:\n/*\n// Basic usage\nthrow new NotFoundError('User not found');\nthrow new BadRequestError('Invalid email format', { field: 'email' });\n\n// With validation errors\nthrow new UnprocessableEntityError('Validation failed', {\n email: 'Invalid email format',\n password: 'Password must be at least 8 characters',\n});\n\n// Type-safe factory function with IntelliSense support\nthrow createHttpError(405, 'Method not allowed', { \n allowedMethods: ['GET', 'POST'] // TypeScript knows this is the correct option!\n});\n\nthrow createHttpError(429, 'Too many requests', { \n retryAfter: 60 // TypeScript knows this needs retryAfter, not details!\n});\n\nthrow createHttpError(422, 'Validation failed', {\n validationErrors: { // TypeScript knows this is for validation errors\n email: 'Invalid format',\n age: 'Must be 18+'\n }\n});\n\n// Using the type-safe createError object\nthrow createError.methodNotAllowed('DELETE not supported', ['GET', 'POST']);\nthrow createError.tooManyRequests('Rate limit exceeded', 60);\nthrow createError.unprocessableEntity('Invalid input', {\n field: 'email',\n message: 'Invalid format'\n});\n\n// TypeScript will show errors for incorrect usage:\n// throw createHttpError(404, 'Not found', { retryAfter: 60 }); // ❌ Type error!\n// throw createError.notFound('User not found', 60); // ❌ Type error!\n\n// Wrapping unknown errors\ntry {\n await someAsyncOperation();\n} catch (error) {\n throw wrapError(error, 500, 'Failed to process request');\n}\n\n// In Express middleware\napp.use(expressErrorHandler);\n\n// Type checking\nif (isClientError(error)) {\n console.log('Client made a bad request');\n}\n*/\n"],"mappings":";;;;;;;;;;;;;;AAeA,IAAa,YAAb,cAA+B,MAAM;;CAEnC,AAAgB;;CAEhB,AAAgB;;CAEhB,AAAgB,cAAc;;CAE9B,AAAgB;;CAEhB,AAAgB;;;;;;;;;;;;CAahB,YACEA,YACAC,SACAC,SAMA;AACA,QAAM,WAAW,SAAS,iBAAiB,aAAa;AACxD,OAAK,OAAO,KAAK,YAAY;AAC7B,OAAK,aAAa;AAClB,OAAK,gBACH,SAAS,iBAAiB,KAAK,wBAAwB,WAAW;AACpE,OAAK,UAAU,SAAS;AACxB,OAAK,OAAO,SAAS;AAGrB,MAAI,SAAS,MACX,MAAK,QAAQ,QAAQ;AAIvB,QAAM,kBAAkB,MAAM,KAAK,YAAY;CAChD;;;;;;;CAQD,IAAI,OAAO;AACT,SAAO,KAAK,UAAU;GACpB,SAAS,KAAK;GACd,MAAM,KAAK;GACX,OAAO,KAAK;EACb,EAAC;CACH;;;;;;;;CASD,AAAQ,wBAAwBF,YAA4B;EAC1D,MAAMG,iBAAyC;GAC7C,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;EACN;AACD,SAAO,eAAe,eAAe;CACtC;;;;;;;CAQD,SAAS;AACP,SAAO;GACL,MAAM,KAAK;GACX,SAAS,KAAK;GACd,YAAY,KAAK;GACjB,eAAe,KAAK;GACpB,MAAM,KAAK;GACX,SAAS,KAAK;GACd,OAAO,KAAK;EACb;CACF;AACF;;;;;;;;;;;;AAe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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,YACAC,SACAC,SAMC;AACD,QAAM,WAAW,SAAS,iBAAiB,aAAa;AACxD,OAAK,OAAO,KAAK,YAAY;AAC7B,OAAK,aAAa;AAClB,OAAK,gBACJ,SAAS,iBAAiB,KAAK,wBAAwB,WAAW;AACnE,OAAK,UAAU,SAAS;AACxB,OAAK,OAAO,SAAS;AAGrB,MAAI,SAAS,MACZ,MAAK,QAAQ,QAAQ;AAGtB,QAAM,kBAAkB,MAAM,KAAK,YAAY;CAC/C;;;;;;;CAQD,IAAI,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B,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"}
package/package.json CHANGED
@@ -1,12 +1,17 @@
1
1
  {
2
2
  "name": "@geekmidas/errors",
3
- "version": "0.1.0",
3
+ "version": "1.0.1",
4
4
  "type": "module",
5
5
  "exports": {
6
6
  ".": {
7
- "types": "./dist/index.d.ts",
8
- "import": "./dist/index.mjs",
9
- "require": "./dist/index.cjs"
7
+ "import": {
8
+ "types": "./dist/index.d.mts",
9
+ "default": "./dist/index.mjs"
10
+ },
11
+ "require": {
12
+ "types": "./dist/index.d.cts",
13
+ "default": "./dist/index.cjs"
14
+ }
10
15
  }
11
16
  },
12
17
  "repository": {