@maroonedsoftware/errors 1.0.0 → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -30,8 +30,8 @@ throw httpError(404);
30
30
  // With custom message
31
31
  throw httpError(400, 'Validation failed');
32
32
 
33
- // With error details (great for form validation)
34
- throw httpError(400).withErrors({
33
+ // With error details
34
+ throw httpError(400).withDetails({
35
35
  email: 'Invalid email format',
36
36
  password: 'Must be at least 8 characters',
37
37
  });
@@ -54,7 +54,7 @@ throw httpError(500).withInternalDetails({
54
54
  });
55
55
 
56
56
  // Combine multiple options
57
- throw httpError(409).withErrors({ username: 'Already taken' }).withCause(dbError).withInternalDetails({ attemptedUsername: 'john_doe' });
57
+ throw httpError(409).withDetails({ username: 'Already taken' }).withCause(dbError).withInternalDetails({ attemptedUsername: 'john_doe' });
58
58
  ```
59
59
 
60
60
  ### Type Guard
@@ -14,7 +14,7 @@ export type HttpStatusMessage<T extends HttpStatusCodes> = (typeof HttpStatusMap
14
14
  *
15
15
  * @example
16
16
  * ```ts
17
- * throw new HttpError(404).withErrors({ field: 'not found' });
17
+ * throw new HttpError(404).withDetails({ field: 'not found' });
18
18
  * ```
19
19
  *
20
20
  * @example
@@ -56,15 +56,15 @@ export declare class HttpError extends Error {
56
56
  /**
57
57
  * Adds error details to the HTTP error and returns the instance for method chaining.
58
58
  *
59
- * @param errors - Object containing field-specific error information.
59
+ * @param details - Object containing field-specific error information.
60
60
  * @returns The HttpError instance for method chaining.
61
61
  *
62
62
  * @example
63
63
  * ```ts
64
- * error.withErrors({ email: 'Invalid email format', password: 'Too short' });
64
+ * error.withDetails({ email: 'Invalid email format', password: 'Too short' });
65
65
  * ```
66
66
  */
67
- withErrors(errors: Record<string, unknown>): HttpError;
67
+ withDetails(details: Record<string, unknown>): HttpError;
68
68
  /**
69
69
  * Adds HTTP headers to the error response and returns the instance for method chaining.
70
70
  *
@@ -1 +1 @@
1
- {"version":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M,EAAE,OAAO,CAAC,GAAG,SAAS;IAKxD;;;;;;;;;;OAUG;IACH,WAAW,CAAC,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,SAAS;IAKvD;;;;;;;;;;OAUG;IACH,SAAS,CAAC,KAAK,EAAE,KAAK,GAAG,SAAS;IAKlC;;;;;;;;;;OAUG;IACH,mBAAmB,CAAC,eAAe,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,SAAS;IAKxE;;;;;;OAMG;IACH,SAAS,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,SAAS;CAKjD;AAED;;;;;;;;;;;;GAYG;AACH,eAAO,MAAM,WAAW,GAAI,OAAO,OAAO,KAAG,KAAK,IAAI,SAErD,CAAC;AAEF;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,SAAS,GAAI,UAAU,SAAS,eAAe,EAAE,aAAa,SAAS,iBAAiB,CAAC,UAAU,CAAC,EAC/G,YAAY,UAAU,EACtB,UAAU,aAAa,cACc,CAAC;AAExC;;;;;;;;;;GAUG;AACH,eAAO,MAAM,iBAAiB,GAAI,OAAO,MAAM,cAAwD,CAAC"}
package/dist/index.js CHANGED
@@ -87,16 +87,16 @@ var HttpError = class _HttpError extends Error {
87
87
  /**
88
88
  * Adds error details to the HTTP error and returns the instance for method chaining.
89
89
  *
90
- * @param errors - Object containing field-specific error information.
90
+ * @param details - Object containing field-specific error information.
91
91
  * @returns The HttpError instance for method chaining.
92
92
  *
93
93
  * @example
94
94
  * ```ts
95
- * error.withErrors({ email: 'Invalid email format', password: 'Too short' });
95
+ * error.withDetails({ email: 'Invalid email format', password: 'Too short' });
96
96
  * ```
97
97
  */
98
- withErrors(errors) {
99
- this.details = errors;
98
+ withDetails(details) {
99
+ this.details = details;
100
100
  return this;
101
101
  }
102
102
  /**
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/http/http.status.map.ts","../src/http/http.error.ts","../src/on.error.decorator.ts","../src/postgres/postgres.error.handler.ts","../src/postgres/postgres.error.decorator.ts"],"sourcesContent":["/**\n * Map of HTTP status codes to their default status messages.\n * Includes both client error (4xx) and server error (5xx) status codes.\n *\n * @example\n * ```ts\n * HttpStatusMap[404] // 'Not Found'\n * HttpStatusMap[500] // 'Internal Server Error'\n * ```\n */\nexport const HttpStatusMap = {\n 400: 'Bad Request',\n 401: 'Unauthorized',\n 402: 'Payment Required',\n 403: 'Forbidden',\n 404: 'Not Found',\n 405: 'Method Not Allowed',\n 406: 'Not Acceptable',\n 407: 'Proxy Authentication Required',\n 408: 'Request Timeout',\n 409: 'Conflict',\n 410: 'Gone',\n 411: 'Length Required',\n 412: 'Precondition Failed',\n 413: 'Payload Too Large',\n 414: 'Request-URI Too Long',\n 415: 'Unsupported Media Type',\n 416: 'Requested Range Not Satisfiable',\n 417: 'Expectation Failed',\n 418: \"I'm a teapot\",\n 421: 'Misdirected Request',\n 422: 'Unprocessable Entity',\n 423: 'Locked',\n 424: 'Failed Dependency',\n 426: 'Upgrade Required',\n 428: 'Precondition Required',\n 429: 'Too Many Requests',\n 431: 'Request Header Fields Too Large',\n 444: 'Connection Closed Without Response',\n 451: 'Unavailable For Legal Reasons',\n 499: 'Client Closed Request',\n 500: 'Internal Server Error',\n 501: 'Not Implemented',\n 502: 'Bad Gateway',\n 503: 'Service Unavailable',\n 504: 'Gateway Timeout',\n 505: 'HTTP Version Not Supported',\n 506: 'Variant Also Negotiates',\n 507: 'Insufficient Storage',\n 508: 'Loop Detected',\n 510: 'Not Extended',\n 511: 'Network Authentication Required',\n 599: 'Network Connect Timeout Error',\n} as const;\n","import { HttpStatusMap } from './http.status.map.js';\n\n/**\n * Type representing valid HTTP status codes from the HttpStatusMap.\n */\nexport type HttpStatusCodes = keyof typeof HttpStatusMap;\n\n/**\n * Type representing the status message for a given HTTP status code.\n * @template T - The HTTP status code type.\n */\nexport type HttpStatusMessage<T extends HttpStatusCodes> = (typeof HttpStatusMap)[T];\n\n/**\n * Custom error class for HTTP errors with support for status codes, details, headers, and error chaining.\n * Extends the native Error class and provides a fluent API for building error responses.\n *\n * @example\n * ```ts\n * throw new HttpError(404).withErrors({ field: 'not found' });\n * ```\n *\n * @example\n * ```ts\n * throw new HttpError(401)\n * .withHeaders({ 'WWW-Authenticate': 'Bearer' })\n * .withCause(originalError);\n * ```\n */\nexport class HttpError extends Error {\n /**\n * Optional validation or error details to include in the response.\n * Typically used for 400-level errors to provide field-specific error information.\n */\n details?: Record<string, unknown>;\n\n /**\n * Optional HTTP headers to include in the error response.\n * Useful for authentication errors (e.g., WWW-Authenticate header).\n */\n headers?: Record<string, string>;\n\n /**\n * Optional underlying error that caused this HTTP error.\n * Follows the Error.cause pattern for error chaining.\n */\n cause?: Error;\n\n /**\n * Optional internal details that should not be exposed to clients.\n * Useful for debugging and logging purposes.\n */\n internalDetails?: Record<string, unknown>;\n\n /**\n * Creates a new HttpError instance.\n *\n * @param statusCode - The HTTP status code (must be a key from HttpStatusMap).\n * @param message - Optional custom error message. If not provided, uses the default message from HttpStatusMap.\n */\n constructor(\n readonly statusCode: HttpStatusCodes,\n message?: HttpStatusMessage<HttpStatusCodes>,\n ) {\n super(message ?? HttpStatusMap[statusCode]);\n\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n (this as any)[Symbol.toStringTag] = 'Object';\n\n // 👇️ because we are extending a built-in class\n Object.setPrototypeOf(this, HttpError.prototype);\n }\n\n /**\n * Adds error details to the HTTP error and returns the instance for method chaining.\n *\n * @param errors - Object containing field-specific error information.\n * @returns The HttpError instance for method chaining.\n *\n * @example\n * ```ts\n * error.withErrors({ email: 'Invalid email format', password: 'Too short' });\n * ```\n */\n withErrors(errors: Record<string, unknown>): HttpError {\n this.details = errors;\n return this;\n }\n\n /**\n * Adds HTTP headers to the error response and returns the instance for method chaining.\n *\n * @param headers - Object containing HTTP header key-value pairs.\n * @returns The HttpError instance for method chaining.\n *\n * @example\n * ```ts\n * error.withHeaders({ 'WWW-Authenticate': 'Bearer realm=\"api\"' });\n * ```\n */\n withHeaders(headers: Record<string, string>): HttpError {\n this.headers = headers;\n return this;\n }\n\n /**\n * Sets the underlying cause of this error and returns the instance for method chaining.\n *\n * @param cause - The original error that caused this HTTP error.\n * @returns The HttpError instance for method chaining.\n *\n * @example\n * ```ts\n * error.withCause(new Error('Database connection failed'));\n * ```\n */\n withCause(cause: Error): HttpError {\n this.cause = cause;\n return this;\n }\n\n /**\n * Adds internal details that should not be exposed to clients and returns the instance for method chaining.\n *\n * @param internalDetails - Object containing internal debugging information.\n * @returns The HttpError instance for method chaining.\n *\n * @example\n * ```ts\n * error.withInternalDetails({ userId: 123, requestId: 'abc-123' });\n * ```\n */\n withInternalDetails(internalDetails: Record<string, unknown>): HttpError {\n this.internalDetails = internalDetails;\n return this;\n }\n\n /**\n * Adds a HTTP header to the error response and returns the instance for method chaining.\n *\n * @param key - The HTTP header key.\n * @param value - The HTTP header value.\n * @returns The HttpError instance for method chaining.\n */\n addHeader(key: string, value: string): HttpError {\n this.headers ??= {};\n this.headers[key] = value;\n return this;\n }\n}\n\n/**\n * Type guard to check if an unknown value is an HttpError instance.\n *\n * @param error - The value to check.\n * @returns True if the value is an HttpError instance, false otherwise.\n *\n * @example\n * ```ts\n * if (IsHttpError(error)) {\n * console.log(error.statusCode);\n * }\n * ```\n */\nexport const IsHttpError = (error: unknown): error is HttpError => {\n return error instanceof HttpError;\n};\n\n/**\n * Factory function to create an HttpError instance with a specific status code.\n *\n * @template StatusCode - The HTTP status code type.\n * @template StatusMessage - The status message type for the given status code.\n * @param statusCode - The HTTP status code.\n * @param message - Optional custom error message.\n * @returns A new HttpError instance.\n *\n * @example\n * ```ts\n * throw httpError(404);\n * ```\n */\nexport const httpError = <StatusCode extends HttpStatusCodes, StatusMessage extends HttpStatusMessage<StatusCode>>(\n statusCode: StatusCode,\n message?: StatusMessage,\n) => new HttpError(statusCode, message);\n\n/**\n * Factory function to create an unauthorized HttpError instance.\n *\n * @param error - The error message of the WWW-Authenticate header.\n * @returns A new HttpError instance with the WWW-Authenticate header set to the given error message.\n *\n * @example\n * ```ts\n * throw unauthorizedError('Bearer realm=\"api\"');\n * ```\n */\nexport const unauthorizedError = (error: string) => httpError(401).addHeader('WWW-Authenticate', error);\n","/* eslint-disable @typescript-eslint/no-unsafe-function-type */\n\n/**\n * Type definition for an error handler function.\n * Called when an error is caught in a decorated method, getter, or setter.\n */\ntype ErrorHandler = (error: Error) => void;\n\n/**\n * Generates a property descriptor that wraps the original method/getter/setter with error handling.\n * For methods, handles both synchronous and asynchronous errors.\n * For getters/setters, wraps the accessor with try-catch.\n *\n * @param descriptor - The original property descriptor to wrap.\n * @param handler - The error handler function to call when an error occurs.\n * @returns A new property descriptor with error handling.\n */\nconst generateDescriptor = (descriptor: PropertyDescriptor, handler: ErrorHandler): PropertyDescriptor => {\n if (!descriptor.value) {\n const getter = descriptor.get;\n const setter = descriptor.set;\n\n if (getter) {\n descriptor.get = () => {\n try {\n return getter.apply(this);\n } catch (error) {\n handler(error as Error);\n }\n };\n }\n\n if (setter) {\n descriptor.set = (v: unknown) => {\n try {\n return setter.apply(this, [v]);\n } catch (error) {\n handler(error as Error);\n }\n };\n }\n\n return descriptor;\n }\n\n const method = descriptor.value;\n\n descriptor.value = function (...args: unknown[]) {\n try {\n const result = method.apply(this, args);\n\n if (result && result instanceof Promise) {\n return result.catch((error: unknown) => {\n handler(error as Error);\n });\n }\n\n return result;\n } catch (error) {\n handler(error as Error);\n }\n };\n\n return descriptor;\n};\n\n/**\n * Class decorator that automatically wraps all methods, getters, and setters in a class\n * with error handling. When any decorated method throws an error (synchronously or asynchronously),\n * the provided error handler is called.\n *\n * The decorator:\n * - Wraps all methods (including async methods) with try-catch\n * - Wraps getters and setters with try-catch\n * - Does not wrap the constructor\n * - Does not wrap non-method properties\n *\n * @param handler - The error handler function to call when an error is caught.\n * @returns A class decorator function.\n *\n * @example\n * ```ts\n * @OnError((error) => {\n * console.error('Error caught:', error);\n * throw new HttpError(500).withCause(error);\n * })\n * class MyService {\n * async doSomething() {\n * throw new Error('Something went wrong');\n * }\n * }\n * ```\n *\n * @example\n * ```ts\n * @OnError(PostgresErrorHandler)\n * class UserRepository {\n * async findById(id: number) {\n * // If this throws a PostgresError, it will be handled\n * return await db.select().from('users').where('id', id);\n * }\n * }\n * ```\n */\nexport const OnError = (handler: ErrorHandler): ClassDecorator => {\n return <TFunction extends Function>(target: TFunction): TFunction => {\n for (const propertyName of Reflect.ownKeys(target.prototype).filter(prop => prop !== 'constructor')) {\n const desc = Object.getOwnPropertyDescriptor(target.prototype, propertyName);\n if (desc) {\n const isMethod = desc.value instanceof Function || desc.get instanceof Function || desc.set instanceof Function;\n if (isMethod) {\n Object.defineProperty(target.prototype, propertyName, generateDescriptor(desc, handler));\n }\n }\n }\n return target;\n };\n};\n","import { httpError } from '../http/http.error.js';\n\n/**\n * Interface representing a PostgreSQL error with a specific error code.\n * PostgreSQL errors include a `code` property that identifies the type of error.\n */\nexport interface PostgresError extends Error {\n /**\n * PostgreSQL error code (e.g., '23505' for unique constraint violation).\n */\n code: string;\n}\n\n/**\n * Type guard to check if an error is a PostgreSQL error with a code property.\n *\n * @param error - The error to check.\n * @returns True if the error has a `code` property, false otherwise.\n *\n * @example\n * ```ts\n * if (isPostgresError(error)) {\n * console.log(error.code); // '23505'\n * }\n * ```\n */\nexport const isPostgresError = (error: Error): error is PostgresError => {\n return 'code' in error;\n};\n\n/**\n * Handles PostgreSQL errors by converting them to appropriate HTTP errors.\n * Maps PostgreSQL error codes to HTTP status codes:\n * - 23505 (unique constraint violation) → 409 Conflict\n * - 23503 (foreign key violation) → 404 Not Found\n * - 23502, 22P02, 22003, 23514 (validation errors) → 400 Bad Request\n * - 40000, 40001, 40002 (transaction rollback) → 500 Internal Server Error\n * - 40P01 (deadlock) → 500 Internal Server Error\n * - Unknown codes → 500 Internal Server Error\n *\n * If the error is not a PostgreSQL error, it is re-thrown as-is.\n *\n * @param error - The error to handle.\n * @throws {HttpError} An HttpError with the appropriate status code and cause.\n * @throws {Error} The original error if it's not a PostgreSQL error.\n *\n * @example\n * ```ts\n * try {\n * await db.insert(...);\n * } catch (error) {\n * PostgresErrorHandler(error); // Converts to HttpError\n * }\n * ```\n */\nexport const PostgresErrorHandler = (error: Error) => {\n if (isPostgresError(error)) {\n switch (error.code) {\n case '23505':\n throw httpError(409).withCause(error);\n case '23503':\n throw httpError(404).withCause(error);\n case '23502':\n case '22P02':\n case '22003':\n case '23514':\n throw httpError(400).withCause(error);\n case '40000':\n case '40001':\n case '40002':\n throw httpError(500).withCause(error).withInternalDetails({ msg: 'Transaction rollback' });\n case '40P01':\n throw httpError(500).withCause(error).withInternalDetails({ msg: 'Deadlock' });\n default:\n throw httpError(500).withCause(error);\n }\n } else {\n throw error;\n }\n};\n","import { PostgresErrorHandler } from './postgres.error.handler.js';\nimport { OnError } from '../on.error.decorator.js';\n\nexport const OnPostgresError = () => OnError(PostgresErrorHandler);\n"],"mappings":";;;;AAUO,IAAMA,gBAAgB;EAC3B,KAAK;EACL,KAAK;EACL,KAAK;EACL,KAAK;EACL,KAAK;EACL,KAAK;EACL,KAAK;EACL,KAAK;EACL,KAAK;EACL,KAAK;EACL,KAAK;EACL,KAAK;EACL,KAAK;EACL,KAAK;EACL,KAAK;EACL,KAAK;EACL,KAAK;EACL,KAAK;EACL,KAAK;EACL,KAAK;EACL,KAAK;EACL,KAAK;EACL,KAAK;EACL,KAAK;EACL,KAAK;EACL,KAAK;EACL,KAAK;EACL,KAAK;EACL,KAAK;EACL,KAAK;EACL,KAAK;EACL,KAAK;EACL,KAAK;EACL,KAAK;EACL,KAAK;EACL,KAAK;EACL,KAAK;EACL,KAAK;EACL,KAAK;EACL,KAAK;EACL,KAAK;EACL,KAAK;AACP;;;ACxBO,IAAMC,YAAN,MAAMA,mBAAkBC,MAAAA;EA7B/B,OA6B+BA;;;;;;;;EAK7BC;;;;;EAMAC;;;;;EAMAC;;;;;EAMAC;;;;;;;EAQA,YACWC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AAK;MACL,KAAK;MACL,KAAK;AACH,cAAMG,UAAU,GAAA,EAAKC,UAAUJ,KAAAA,EAAOK,oBAAoB;UAAEC,KAAK;QAAuB,CAAA;MAC1F,KAAK;AACH,cAAMH,UAAU,GAAA,EAAKC,UAAUJ,KAAAA,EAAOK,oBAAoB;UAAEC,KAAK;QAAW,CAAA;MAC9E;AACE,cAAMH,UAAU,GAAA,EAAKC,UAAUJ,KAAAA;IACnC;EACF,OAAO;AACL,UAAMA;EACR;AACF,GAxBoC;;;ACpD7B,IAAMO,kBAAkB,6BAAMC,QAAQC,oBAAAA,GAAd;","names":["HttpStatusMap","HttpError","Error","details","headers","cause","internalDetails","statusCode","message","HttpStatusMap","Symbol","toStringTag","Object","setPrototypeOf","prototype","withErrors","errors","withHeaders","withCause","withInternalDetails","addHeader","key","value","IsHttpError","error","httpError","unauthorizedError","generateDescriptor","descriptor","handler","value","getter","get","setter","set","apply","error","v","method","args","result","Promise","catch","OnError","target","propertyName","Reflect","ownKeys","prototype","filter","prop","desc","Object","getOwnPropertyDescriptor","isMethod","Function","defineProperty","isPostgresError","error","PostgresErrorHandler","code","httpError","withCause","withInternalDetails","msg","OnPostgresError","OnError","PostgresErrorHandler"]}
1
+ {"version":3,"sources":["../src/http/http.status.map.ts","../src/http/http.error.ts","../src/on.error.decorator.ts","../src/postgres/postgres.error.handler.ts","../src/postgres/postgres.error.decorator.ts"],"sourcesContent":["/**\n * Map of HTTP status codes to their default status messages.\n * Includes both client error (4xx) and server error (5xx) status codes.\n *\n * @example\n * ```ts\n * HttpStatusMap[404] // 'Not Found'\n * HttpStatusMap[500] // 'Internal Server Error'\n * ```\n */\nexport const HttpStatusMap = {\n 400: 'Bad Request',\n 401: 'Unauthorized',\n 402: 'Payment Required',\n 403: 'Forbidden',\n 404: 'Not Found',\n 405: 'Method Not Allowed',\n 406: 'Not Acceptable',\n 407: 'Proxy Authentication Required',\n 408: 'Request Timeout',\n 409: 'Conflict',\n 410: 'Gone',\n 411: 'Length Required',\n 412: 'Precondition Failed',\n 413: 'Payload Too Large',\n 414: 'Request-URI Too Long',\n 415: 'Unsupported Media Type',\n 416: 'Requested Range Not Satisfiable',\n 417: 'Expectation Failed',\n 418: \"I'm a teapot\",\n 421: 'Misdirected Request',\n 422: 'Unprocessable Entity',\n 423: 'Locked',\n 424: 'Failed Dependency',\n 426: 'Upgrade Required',\n 428: 'Precondition Required',\n 429: 'Too Many Requests',\n 431: 'Request Header Fields Too Large',\n 444: 'Connection Closed Without Response',\n 451: 'Unavailable For Legal Reasons',\n 499: 'Client Closed Request',\n 500: 'Internal Server Error',\n 501: 'Not Implemented',\n 502: 'Bad Gateway',\n 503: 'Service Unavailable',\n 504: 'Gateway Timeout',\n 505: 'HTTP Version Not Supported',\n 506: 'Variant Also Negotiates',\n 507: 'Insufficient Storage',\n 508: 'Loop Detected',\n 510: 'Not Extended',\n 511: 'Network Authentication Required',\n 599: 'Network Connect Timeout Error',\n} as const;\n","import { HttpStatusMap } from './http.status.map.js';\n\n/**\n * Type representing valid HTTP status codes from the HttpStatusMap.\n */\nexport type HttpStatusCodes = keyof typeof HttpStatusMap;\n\n/**\n * Type representing the status message for a given HTTP status code.\n * @template T - The HTTP status code type.\n */\nexport type HttpStatusMessage<T extends HttpStatusCodes> = (typeof HttpStatusMap)[T];\n\n/**\n * Custom error class for HTTP errors with support for status codes, details, headers, and error chaining.\n * Extends the native Error class and provides a fluent API for building error responses.\n *\n * @example\n * ```ts\n * throw new HttpError(404).withDetails({ field: 'not found' });\n * ```\n *\n * @example\n * ```ts\n * throw new HttpError(401)\n * .withHeaders({ 'WWW-Authenticate': 'Bearer' })\n * .withCause(originalError);\n * ```\n */\nexport class HttpError extends Error {\n /**\n * Optional validation or error details to include in the response.\n * Typically used for 400-level errors to provide field-specific error information.\n */\n details?: Record<string, unknown>;\n\n /**\n * Optional HTTP headers to include in the error response.\n * Useful for authentication errors (e.g., WWW-Authenticate header).\n */\n headers?: Record<string, string>;\n\n /**\n * Optional underlying error that caused this HTTP error.\n * Follows the Error.cause pattern for error chaining.\n */\n cause?: Error;\n\n /**\n * Optional internal details that should not be exposed to clients.\n * Useful for debugging and logging purposes.\n */\n internalDetails?: Record<string, unknown>;\n\n /**\n * Creates a new HttpError instance.\n *\n * @param statusCode - The HTTP status code (must be a key from HttpStatusMap).\n * @param message - Optional custom error message. If not provided, uses the default message from HttpStatusMap.\n */\n constructor(\n readonly statusCode: HttpStatusCodes,\n message?: HttpStatusMessage<HttpStatusCodes>,\n ) {\n super(message ?? HttpStatusMap[statusCode]);\n\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n (this as any)[Symbol.toStringTag] = 'Object';\n\n // 👇️ because we are extending a built-in class\n Object.setPrototypeOf(this, HttpError.prototype);\n }\n\n /**\n * Adds error details to the HTTP error and returns the instance for method chaining.\n *\n * @param details - Object containing field-specific error information.\n * @returns The HttpError instance for method chaining.\n *\n * @example\n * ```ts\n * error.withDetails({ email: 'Invalid email format', password: 'Too short' });\n * ```\n */\n withDetails(details: Record<string, unknown>): HttpError {\n this.details = details;\n return this;\n }\n\n /**\n * Adds HTTP headers to the error response and returns the instance for method chaining.\n *\n * @param headers - Object containing HTTP header key-value pairs.\n * @returns The HttpError instance for method chaining.\n *\n * @example\n * ```ts\n * error.withHeaders({ 'WWW-Authenticate': 'Bearer realm=\"api\"' });\n * ```\n */\n withHeaders(headers: Record<string, string>): HttpError {\n this.headers = headers;\n return this;\n }\n\n /**\n * Sets the underlying cause of this error and returns the instance for method chaining.\n *\n * @param cause - The original error that caused this HTTP error.\n * @returns The HttpError instance for method chaining.\n *\n * @example\n * ```ts\n * error.withCause(new Error('Database connection failed'));\n * ```\n */\n withCause(cause: Error): HttpError {\n this.cause = cause;\n return this;\n }\n\n /**\n * Adds internal details that should not be exposed to clients and returns the instance for method chaining.\n *\n * @param internalDetails - Object containing internal debugging information.\n * @returns The HttpError instance for method chaining.\n *\n * @example\n * ```ts\n * error.withInternalDetails({ userId: 123, requestId: 'abc-123' });\n * ```\n */\n withInternalDetails(internalDetails: Record<string, unknown>): HttpError {\n this.internalDetails = internalDetails;\n return this;\n }\n\n /**\n * Adds a HTTP header to the error response and returns the instance for method chaining.\n *\n * @param key - The HTTP header key.\n * @param value - The HTTP header value.\n * @returns The HttpError instance for method chaining.\n */\n addHeader(key: string, value: string): HttpError {\n this.headers ??= {};\n this.headers[key] = value;\n return this;\n }\n}\n\n/**\n * Type guard to check if an unknown value is an HttpError instance.\n *\n * @param error - The value to check.\n * @returns True if the value is an HttpError instance, false otherwise.\n *\n * @example\n * ```ts\n * if (IsHttpError(error)) {\n * console.log(error.statusCode);\n * }\n * ```\n */\nexport const IsHttpError = (error: unknown): error is HttpError => {\n return error instanceof HttpError;\n};\n\n/**\n * Factory function to create an HttpError instance with a specific status code.\n *\n * @template StatusCode - The HTTP status code type.\n * @template StatusMessage - The status message type for the given status code.\n * @param statusCode - The HTTP status code.\n * @param message - Optional custom error message.\n * @returns A new HttpError instance.\n *\n * @example\n * ```ts\n * throw httpError(404);\n * ```\n */\nexport const httpError = <StatusCode extends HttpStatusCodes, StatusMessage extends HttpStatusMessage<StatusCode>>(\n statusCode: StatusCode,\n message?: StatusMessage,\n) => new HttpError(statusCode, message);\n\n/**\n * Factory function to create an unauthorized HttpError instance.\n *\n * @param error - The error message of the WWW-Authenticate header.\n * @returns A new HttpError instance with the WWW-Authenticate header set to the given error message.\n *\n * @example\n * ```ts\n * throw unauthorizedError('Bearer realm=\"api\"');\n * ```\n */\nexport const unauthorizedError = (error: string) => httpError(401).addHeader('WWW-Authenticate', error);\n","/* eslint-disable @typescript-eslint/no-unsafe-function-type */\n\n/**\n * Type definition for an error handler function.\n * Called when an error is caught in a decorated method, getter, or setter.\n */\ntype ErrorHandler = (error: Error) => void;\n\n/**\n * Generates a property descriptor that wraps the original method/getter/setter with error handling.\n * For methods, handles both synchronous and asynchronous errors.\n * For getters/setters, wraps the accessor with try-catch.\n *\n * @param descriptor - The original property descriptor to wrap.\n * @param handler - The error handler function to call when an error occurs.\n * @returns A new property descriptor with error handling.\n */\nconst generateDescriptor = (descriptor: PropertyDescriptor, handler: ErrorHandler): PropertyDescriptor => {\n if (!descriptor.value) {\n const getter = descriptor.get;\n const setter = descriptor.set;\n\n if (getter) {\n descriptor.get = () => {\n try {\n return getter.apply(this);\n } catch (error) {\n handler(error as Error);\n }\n };\n }\n\n if (setter) {\n descriptor.set = (v: unknown) => {\n try {\n return setter.apply(this, [v]);\n } catch (error) {\n handler(error as Error);\n }\n };\n }\n\n return descriptor;\n }\n\n const method = descriptor.value;\n\n descriptor.value = function (...args: unknown[]) {\n try {\n const result = method.apply(this, args);\n\n if (result && result instanceof Promise) {\n return result.catch((error: unknown) => {\n handler(error as Error);\n });\n }\n\n return result;\n } catch (error) {\n handler(error as Error);\n }\n };\n\n return descriptor;\n};\n\n/**\n * Class decorator that automatically wraps all methods, getters, and setters in a class\n * with error handling. When any decorated method throws an error (synchronously or asynchronously),\n * the provided error handler is called.\n *\n * The decorator:\n * - Wraps all methods (including async methods) with try-catch\n * - Wraps getters and setters with try-catch\n * - Does not wrap the constructor\n * - Does not wrap non-method properties\n *\n * @param handler - The error handler function to call when an error is caught.\n * @returns A class decorator function.\n *\n * @example\n * ```ts\n * @OnError((error) => {\n * console.error('Error caught:', error);\n * throw new HttpError(500).withCause(error);\n * })\n * class MyService {\n * async doSomething() {\n * throw new Error('Something went wrong');\n * }\n * }\n * ```\n *\n * @example\n * ```ts\n * @OnError(PostgresErrorHandler)\n * class UserRepository {\n * async findById(id: number) {\n * // If this throws a PostgresError, it will be handled\n * return await db.select().from('users').where('id', id);\n * }\n * }\n * ```\n */\nexport const OnError = (handler: ErrorHandler): ClassDecorator => {\n return <TFunction extends Function>(target: TFunction): TFunction => {\n for (const propertyName of Reflect.ownKeys(target.prototype).filter(prop => prop !== 'constructor')) {\n const desc = Object.getOwnPropertyDescriptor(target.prototype, propertyName);\n if (desc) {\n const isMethod = desc.value instanceof Function || desc.get instanceof Function || desc.set instanceof Function;\n if (isMethod) {\n Object.defineProperty(target.prototype, propertyName, generateDescriptor(desc, handler));\n }\n }\n }\n return target;\n };\n};\n","import { httpError } from '../http/http.error.js';\n\n/**\n * Interface representing a PostgreSQL error with a specific error code.\n * PostgreSQL errors include a `code` property that identifies the type of error.\n */\nexport interface PostgresError extends Error {\n /**\n * PostgreSQL error code (e.g., '23505' for unique constraint violation).\n */\n code: string;\n}\n\n/**\n * Type guard to check if an error is a PostgreSQL error with a code property.\n *\n * @param error - The error to check.\n * @returns True if the error has a `code` property, false otherwise.\n *\n * @example\n * ```ts\n * if (isPostgresError(error)) {\n * console.log(error.code); // '23505'\n * }\n * ```\n */\nexport const isPostgresError = (error: Error): error is PostgresError => {\n return 'code' in error;\n};\n\n/**\n * Handles PostgreSQL errors by converting them to appropriate HTTP errors.\n * Maps PostgreSQL error codes to HTTP status codes:\n * - 23505 (unique constraint violation) → 409 Conflict\n * - 23503 (foreign key violation) → 404 Not Found\n * - 23502, 22P02, 22003, 23514 (validation errors) → 400 Bad Request\n * - 40000, 40001, 40002 (transaction rollback) → 500 Internal Server Error\n * - 40P01 (deadlock) → 500 Internal Server Error\n * - Unknown codes → 500 Internal Server Error\n *\n * If the error is not a PostgreSQL error, it is re-thrown as-is.\n *\n * @param error - The error to handle.\n * @throws {HttpError} An HttpError with the appropriate status code and cause.\n * @throws {Error} The original error if it's not a PostgreSQL error.\n *\n * @example\n * ```ts\n * try {\n * await db.insert(...);\n * } catch (error) {\n * PostgresErrorHandler(error); // Converts to HttpError\n * }\n * ```\n */\nexport const PostgresErrorHandler = (error: Error) => {\n if (isPostgresError(error)) {\n switch (error.code) {\n case '23505':\n throw httpError(409).withCause(error);\n case '23503':\n throw httpError(404).withCause(error);\n case '23502':\n case '22P02':\n case '22003':\n case '23514':\n throw httpError(400).withCause(error);\n case '40000':\n case '40001':\n case '40002':\n throw httpError(500).withCause(error).withInternalDetails({ msg: 'Transaction rollback' });\n case '40P01':\n throw httpError(500).withCause(error).withInternalDetails({ msg: 'Deadlock' });\n default:\n throw httpError(500).withCause(error);\n }\n } else {\n throw error;\n }\n};\n","import { PostgresErrorHandler } from './postgres.error.handler.js';\nimport { OnError } from '../on.error.decorator.js';\n\nexport const OnPostgresError = () => OnError(PostgresErrorHandler);\n"],"mappings":";;;;AAUO,IAAMA,gBAAgB;EAC3B,KAAK;EACL,KAAK;EACL,KAAK;EACL,KAAK;EACL,KAAK;EACL,KAAK;EACL,KAAK;EACL,KAAK;EACL,KAAK;EACL,KAAK;EACL,KAAK;EACL,KAAK;EACL,KAAK;EACL,KAAK;EACL,KAAK;EACL,KAAK;EACL,KAAK;EACL,KAAK;EACL,KAAK;EACL,KAAK;EACL,KAAK;EACL,KAAK;EACL,KAAK;EACL,KAAK;EACL,KAAK;EACL,KAAK;EACL,KAAK;EACL,KAAK;EACL,KAAK;EACL,KAAK;EACL,KAAK;EACL,KAAK;EACL,KAAK;EACL,KAAK;EACL,KAAK;EACL,KAAK;EACL,KAAK;EACL,KAAK;EACL,KAAK;EACL,KAAK;EACL,KAAK;EACL,KAAK;AACP;;;ACxBO,IAAMC,YAAN,MAAMA,mBAAkBC,MAAAA;EA7B/B,OA6B+BA;;;;;;;;EAK7BC;;;;;EAMAC;;;;;EAMAC;;;;;EAMAC;;;;;;;EAQA,YACWC,YACTC,SACA;AACA,UAAMA,WAAWC,cAAcF,UAAAA,CAAW,GAAA,KAHjCA,aAAAA;AAMR,SAAaG,OAAOC,WAAW,IAAI;AAGpCC,WAAOC,eAAe,MAAMZ,WAAUa,SAAS;EACjD;;;;;;;;;;;;EAaAC,YAAYZ,SAA6C;AACvD,SAAKA,UAAUA;AACf,WAAO;EACT;;;;;;;;;;;;EAaAa,YAAYZ,SAA4C;AACtD,SAAKA,UAAUA;AACf,WAAO;EACT;;;;;;;;;;;;EAaAa,UAAUZ,OAAyB;AACjC,SAAKA,QAAQA;AACb,WAAO;EACT;;;;;;;;;;;;EAaAa,oBAAoBZ,iBAAqD;AACvE,SAAKA,kBAAkBA;AACvB,W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C,eAAWC,gBAAgBC,QAAQC,QAAQH,OAAOI,SAAS,EAAEC,OAAOC,CAAAA,SAAQA,SAAS,aAAA,GAAgB;AACnG,YAAMC,OAAOC,OAAOC,yBAAyBT,OAAOI,WAAWH,YAAAA;AAC/D,UAAIM,MAAM;AACR,cAAMG,WAAWH,KAAKrB,iBAAiByB,YAAYJ,KAAKnB,eAAeuB,YAAYJ,KAAKjB,eAAeqB;AACvG,YAAID,UAAU;AACZF,iBAAOI,eAAeZ,OAAOI,WAAWH,cAAclB,mBAAmBwB,MAAMtB,OAAAA,CAAAA;QACjF;MACF;IACF;AACA,WAAOe;EACT;AACF,GAbuB;;;AC9EhB,IAAMa,kBAAkB,wBAACC,UAAAA;AAC9B,SAAO,UAAUA;AACnB,GAF+B;AA6BxB,IAAMC,uBAAuB,wBAACD,UAAAA;AACnC,MAAID,gBAAgBC,KAAAA,GAAQ;AAC1B,YAAQA,MAAME,MAAI;MAChB,KAAK;AACH,cAAMC,UAAU,GAAA,EAAKC,UAAUJ,KAAAA;MACjC,KAAK;AACH,cAAMG,UAAU,GAAA,EAAKC,UAAUJ,KAAAA;MACjC,KAAK;MACL,KAAK;MACL,KAAK;MACL,KAAK;AACH,cAAMG,UAAU,GAAA,EAAKC,UAAUJ,KAAAA;MACjC,KAAK;MACL,KAAK;MACL,KAAK;AACH,cAAMG,UAAU,GAAA,EAAKC,UAAUJ,KAAAA,EAAOK,oBAAoB;UAAEC,KAAK;QAAuB,CAAA;MAC1F,KAAK;AACH,cAAMH,UAAU,GAAA,EAAKC,UAAUJ,KAAAA,EAAOK,oBAAoB;UAAEC,KAAK;QAAW,CAAA;MAC9E;AACE,cAAMH,UAAU,GAAA,EAAKC,UAAUJ,KAAAA;IACnC;EACF,OAAO;AACL,UAAMA;EACR;AACF,GAxBoC;;;ACpD7B,IAAMO,kBAAkB,6BAAMC,QAAQC,oBAAAA,GAAd;","names":["HttpStatusMap","HttpError","Error","details","headers","cause","internalDetails","statusCode","message","HttpStatusMap","Symbol","toStringTag","Object","setPrototypeOf","prototype","withDetails","withHeaders","withCause","withInternalDetails","addHeader","key","value","IsHttpError","error","httpError","unauthorizedError","generateDescriptor","descriptor","handler","value","getter","get","setter","set","apply","error","v","method","args","result","Promise","catch","OnError","target","propertyName","Reflect","ownKeys","prototype","filter","prop","desc","Object","getOwnPropertyDescriptor","isMethod","Function","defineProperty","isPostgresError","error","PostgresErrorHandler","code","httpError","withCause","withInternalDetails","msg","OnPostgresError","OnError","PostgresErrorHandler"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@maroonedsoftware/errors",
3
- "version": "1.0.0",
3
+ "version": "1.1.0",
4
4
  "description": "A comprehensive error handling library for HTTP APIs with built-in support for PostgreSQL error mapping and class-level error decorators.",
5
5
  "author": {
6
6
  "name": "Marooned Software",