nestjs-exception-handler 4.5.1 → 4.6.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
@@ -20,7 +20,7 @@ This package ensures **every error response follows the same standardized format
20
20
 
21
21
  - **Standardized Error Responses**: Consistent error format across your entire application
22
22
  - **ValidationPipe Support**: Automatic extraction and normalization of class-validator errors
23
- - **Prisma Integration**: Built-in support for Prisma error codes (P2002, P2003, P2005, P2006, P2025)
23
+ - **Prisma Integration**: Built-in support for Prisma error codes (P2002, P2003, P2005, P2006, P2025) - works with Prisma 5.x through 7.x
24
24
  - **HttpException Handling**: Handles all NestJS HTTP exceptions with proper formatting
25
25
  - **404 Route Handling**: Converts unmatched routes to standardized format
26
26
  - **Unknown Error Handling**: Safe fallback for unexpected errors without leaking stack traces
@@ -28,6 +28,7 @@ This package ensures **every error response follows the same standardized format
28
28
  - **Type Safe**: Full TypeScript support with zero `any` types
29
29
  - **Production Ready**: Configurable logging and stack trace control
30
30
  - **NestJS v10 & v11 Compatible**: Works with both major versions
31
+ - **Prisma v5 - v7 Compatible**: Works with Prisma 5.x, 6.x, and 7.x
31
32
 
32
33
  ## Installation
33
34
 
package/dist/index.d.mts CHANGED
@@ -1,5 +1,4 @@
1
1
  import { HttpException, ExceptionFilter, ArgumentsHost, DynamicModule } from '@nestjs/common';
2
- import { PrismaClientKnownRequestError, PrismaClientValidationError, PrismaClientRustPanicError, PrismaClientInitializationError } from '@prisma/client/runtime/library';
3
2
 
4
3
  interface ErrorMessage {
5
4
  path: string;
@@ -27,7 +26,12 @@ declare class ValidationErrorFormatter {
27
26
  private formatNestedValidationErrors;
28
27
  }
29
28
 
30
- type PrismaError = PrismaClientKnownRequestError | PrismaClientValidationError | PrismaClientRustPanicError | PrismaClientInitializationError | unknown;
29
+ interface PrismaError {
30
+ code?: string;
31
+ meta?: Record<string, unknown>;
32
+ message?: string;
33
+ clientVersion?: string;
34
+ }
31
35
  declare class PrismaExceptionFormatter implements ExceptionFormatter {
32
36
  supports(exception: unknown): boolean;
33
37
  format(exception: unknown): ErrorMessage[];
package/dist/index.d.ts CHANGED
@@ -1,5 +1,4 @@
1
1
  import { HttpException, ExceptionFilter, ArgumentsHost, DynamicModule } from '@nestjs/common';
2
- import { PrismaClientKnownRequestError, PrismaClientValidationError, PrismaClientRustPanicError, PrismaClientInitializationError } from '@prisma/client/runtime/library';
3
2
 
4
3
  interface ErrorMessage {
5
4
  path: string;
@@ -27,7 +26,12 @@ declare class ValidationErrorFormatter {
27
26
  private formatNestedValidationErrors;
28
27
  }
29
28
 
30
- type PrismaError = PrismaClientKnownRequestError | PrismaClientValidationError | PrismaClientRustPanicError | PrismaClientInitializationError | unknown;
29
+ interface PrismaError {
30
+ code?: string;
31
+ meta?: Record<string, unknown>;
32
+ message?: string;
33
+ clientVersion?: string;
34
+ }
31
35
  declare class PrismaExceptionFormatter implements ExceptionFormatter {
32
36
  supports(exception: unknown): boolean;
33
37
  format(exception: unknown): ErrorMessage[];
package/dist/index.js CHANGED
@@ -76,10 +76,16 @@ var ValidationErrorFormatter = class {
76
76
 
77
77
  // src/formatters/prisma-exception.formatter.ts
78
78
  var import_common = require("@nestjs/common");
79
- var import_library = require("@prisma/client/runtime/library");
80
79
  var PrismaExceptionFormatter = class {
81
80
  supports(exception) {
82
- return exception instanceof import_library.PrismaClientKnownRequestError || exception instanceof import_library.PrismaClientValidationError || exception instanceof import_library.PrismaClientRustPanicError || exception instanceof import_library.PrismaClientInitializationError;
81
+ if (!exception || typeof exception !== "object") {
82
+ return false;
83
+ }
84
+ const error = exception;
85
+ const hasErrorCode = typeof error.code === "string";
86
+ const hasClientVersion = typeof error.clientVersion === "string";
87
+ const hasMeta = typeof error.meta === "object";
88
+ return hasErrorCode || hasClientVersion && hasMeta;
83
89
  }
84
90
  format(exception) {
85
91
  return this.formatError(exception);
@@ -88,13 +94,15 @@ var PrismaExceptionFormatter = class {
88
94
  return "Database error";
89
95
  }
90
96
  formatError(exception) {
91
- if (exception instanceof import_library.PrismaClientKnownRequestError) {
97
+ const code = exception.code;
98
+ if (code) {
92
99
  return this.formatPrismaError(exception);
93
100
  }
94
- if (exception instanceof import_library.PrismaClientValidationError || exception instanceof import_library.PrismaClientRustPanicError) {
101
+ const message = exception.message || "";
102
+ if (message.includes("validation") || message.includes("Rust") || message.includes("panic")) {
95
103
  return this.formatQueryError(exception);
96
104
  }
97
- if (exception instanceof import_library.PrismaClientInitializationError) {
105
+ if (message.includes("initialization") || message.includes("connect")) {
98
106
  return this.formatInitializationError(exception);
99
107
  }
100
108
  return this.formatUnknownError(exception);
@@ -158,14 +166,15 @@ var PrismaExceptionFormatter = class {
158
166
  }
159
167
  }
160
168
  formatQueryError(exception) {
161
- let message = "Invalid database query.";
162
- if (exception instanceof import_library.PrismaClientRustPanicError) {
163
- message = "Database engine panic occurred.";
169
+ const message = exception.message || "";
170
+ let errorMessage = "Invalid database query.";
171
+ if (message.includes("panic")) {
172
+ errorMessage = "Database engine panic occurred.";
164
173
  }
165
174
  return [
166
175
  {
167
176
  path: "database",
168
- message: [message]
177
+ message: [errorMessage]
169
178
  }
170
179
  ];
171
180
  }
@@ -173,7 +182,7 @@ var PrismaExceptionFormatter = class {
173
182
  return [
174
183
  {
175
184
  path: "database",
176
- message: [`Database initialization error: ${exception.message}`]
185
+ message: [`Database initialization error: ${exception.message || "Unknown error"}`]
177
186
  }
178
187
  ];
179
188
  }
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.ts","../src/formatters/validation-error.formatter.ts","../src/formatters/prisma-exception.formatter.ts","../src/formatters/dto-validation.formatter.ts","../src/filter/global-exception.filter.ts","../src/services/exception-handler.service.ts","../src/formatters/http-exception.formatter.ts","../src/formatters/dto-exception.formatter.ts","../src/constants/default-messages.ts","../src/formatters/unknown-exception.formatter.ts","../src/module/exception-handler.module.ts","../src/utils/http-error.formatter.ts"],"sourcesContent":["export * from './interfaces';\nexport * from './formatters/validation-error.formatter';\nexport * from './formatters/prisma-exception.formatter';\nexport * from './formatters/dto-validation.formatter';\nexport * from './filter/global-exception.filter';\nexport * from './module/exception-handler.module';\nexport * from './services/exception-handler.service';\nexport * from './utils/http-error.formatter';\n","import { HttpException, ValidationError } from '@nestjs/common';\nimport { ErrorMessage } from '../interfaces/error-message.interface';\n\nexport class ValidationErrorFormatter {\n formatValidationErrors(exception: HttpException): ErrorMessage[] {\n const response = exception.getResponse();\n\n if (typeof response === 'object' && response !== null) {\n const responseObj = response as Record<string, unknown>;\n\n if (Array.isArray(responseObj.message)) {\n const messages = responseObj.message;\n\n if (messages.length > 0 && typeof messages[0] === 'object' && 'property' in messages[0]) {\n return this.formatNestedValidationErrors(messages as ValidationError[]);\n }\n\n return [\n {\n path: 'http_error',\n message: messages as string[],\n },\n ];\n }\n }\n\n return [\n {\n path: 'http_error',\n message: ['Validation failed'],\n },\n ];\n }\n\n private formatNestedValidationErrors(errors: ValidationError[]): ErrorMessage[] {\n return errors.map((error) => ({\n path: error.property,\n message: error.constraints ? Object.values(error.constraints) : ['Validation error'],\n }));\n }\n}\n","import { Injectable } from '@nestjs/common';\nimport {\n PrismaClientKnownRequestError,\n PrismaClientValidationError,\n PrismaClientRustPanicError,\n PrismaClientInitializationError,\n} from '@prisma/client/runtime/library';\nimport { ErrorMessage } from '../interfaces/error-message.interface';\nimport { ExceptionFormatter } from '../interfaces/exception-formatter.interface';\n\ntype PrismaError =\n | PrismaClientKnownRequestError\n | PrismaClientValidationError\n | PrismaClientRustPanicError\n | PrismaClientInitializationError\n | unknown;\n\n@Injectable()\nexport class PrismaExceptionFormatter implements ExceptionFormatter {\n supports(exception: unknown): boolean {\n return (\n exception instanceof PrismaClientKnownRequestError ||\n exception instanceof PrismaClientValidationError ||\n exception instanceof PrismaClientRustPanicError ||\n exception instanceof PrismaClientInitializationError\n );\n }\n\n format(exception: unknown): ErrorMessage[] {\n return this.formatError(exception as PrismaError);\n }\n\n message(_exception: unknown): string {\n return 'Database error';\n }\n\n formatError(exception: PrismaError): ErrorMessage[] {\n if (exception instanceof PrismaClientKnownRequestError) {\n return this.formatPrismaError(exception);\n }\n\n if (\n exception instanceof PrismaClientValidationError ||\n exception instanceof PrismaClientRustPanicError\n ) {\n return this.formatQueryError(exception);\n }\n\n if (exception instanceof PrismaClientInitializationError) {\n return this.formatInitializationError(exception);\n }\n\n return this.formatUnknownError(exception);\n }\n\n private formatPrismaError(exception: PrismaClientKnownRequestError): ErrorMessage[] {\n const code = exception.code;\n const meta = exception.meta as Record<string, unknown> | undefined;\n\n switch (code) {\n case 'P2002': {\n const target = meta?.target as string[] | undefined;\n const field = target?.[0] || 'field';\n return [\n {\n path: field,\n message: [`A record with this ${field} already exists.`],\n },\n ];\n }\n case 'P2003': {\n const fieldName = meta?.field_name as string | undefined;\n return [\n {\n path: fieldName || 'field',\n message: [`The referenced ${fieldName || 'record'} does not exist.`],\n },\n ];\n }\n case 'P2005': {\n const fieldName = meta?.field_name as string | undefined;\n return [\n {\n path: fieldName || 'field',\n message: [`The value for ${fieldName || 'field'} is invalid.`],\n },\n ];\n }\n case 'P2006': {\n const fieldName = meta?.field_name as string | undefined;\n return [\n {\n path: fieldName || 'field',\n message: [`The ${fieldName || 'field'} field is required.`],\n },\n ];\n }\n case 'P2025': {\n return [\n {\n path: 'record',\n message: ['The requested record does not exist.'],\n },\n ];\n }\n default:\n return [\n {\n path: 'database',\n message: ['Database operation failed.'],\n },\n ];\n }\n }\n\n private formatQueryError(\n exception: PrismaClientValidationError | PrismaClientRustPanicError,\n ): ErrorMessage[] {\n let message = 'Invalid database query.';\n\n if (exception instanceof PrismaClientRustPanicError) {\n message = 'Database engine panic occurred.';\n }\n\n return [\n {\n path: 'database',\n message: [message],\n },\n ];\n }\n\n private formatInitializationError(exception: PrismaClientInitializationError): ErrorMessage[] {\n return [\n {\n path: 'database',\n message: [`Database initialization error: ${exception.message}`],\n },\n ];\n }\n\n private formatUnknownError(exception: unknown): ErrorMessage[] {\n return [\n {\n path: 'unknown',\n message:\n exception instanceof Error\n ? [exception.message]\n : ['An unexpected database error occurred.'],\n },\n ];\n }\n}\n","import { Injectable } from '@nestjs/common';\nimport { HttpException } from '@nestjs/common';\nimport { ErrorMessage } from '../interfaces/error-message.interface';\n\ninterface ValidationError {\n property: string;\n constraints?: Record<string, string>;\n children?: ValidationError[];\n}\n\n@Injectable()\nexport class DtoValidationFormatter {\n formatDtoValidationException(exception: HttpException): ErrorMessage[] {\n const responseBody: unknown = exception.getResponse();\n\n if (\n typeof responseBody === 'object' &&\n responseBody !== null &&\n 'message' in responseBody &&\n Array.isArray((responseBody as Record<string, unknown>).message)\n ) {\n const messages = (responseBody as Record<string, unknown>).message as unknown[];\n const firstMessage = messages[0];\n\n if (\n firstMessage &&\n typeof firstMessage === 'object' &&\n firstMessage !== null &&\n 'property' in firstMessage\n ) {\n const validationErrors = messages as ValidationError[];\n return validationErrors.map((error: ValidationError) => ({\n path: error.property,\n message: error.constraints ? Object.values(error.constraints) : ['Validation error'],\n }));\n }\n\n if (typeof firstMessage === 'string') {\n return [\n {\n path: 'http_error',\n message: messages as string[],\n },\n ];\n }\n }\n\n return [\n {\n path: 'http_error',\n message:\n typeof responseBody === 'object' && responseBody !== null && 'message' in responseBody\n ? [(responseBody as Record<string, unknown>).message as string]\n : ['An HTTP error occurred'],\n },\n ];\n }\n}\n","import {\n ExceptionFilter,\n Catch,\n ArgumentsHost,\n HttpException,\n HttpStatus,\n Logger,\n NotFoundException,\n} from '@nestjs/common';\nimport { Request, Response } from 'express';\nimport { ExceptionHandlerService } from '../services/exception-handler.service';\nimport { ErrorResponse, ErrorMessage } from '../interfaces/error-message.interface';\nimport { ExceptionHandlerConfig } from '../interfaces/exception-handler-config.interface';\n\n@Catch()\nexport class GlobalExceptionFilter implements ExceptionFilter {\n private readonly logger = new Logger(GlobalExceptionFilter.name);\n private config: ExceptionHandlerConfig;\n\n constructor(\n private exceptionHandlerService?: ExceptionHandlerService,\n config?: ExceptionHandlerConfig,\n ) {\n this.config = config || { enableLogging: true, hideStackTrace: false };\n }\n\n private getService(): ExceptionHandlerService {\n if (!this.exceptionHandlerService) {\n this.exceptionHandlerService = new ExceptionHandlerService();\n }\n return this.exceptionHandlerService;\n }\n\n catch(exception: unknown, host: ArgumentsHost): void {\n const ctx = host.switchToHttp();\n const response = ctx.getResponse<Response>();\n const request = ctx.getRequest<Request>();\n\n const { errors, message } = this.getService().formatException(exception);\n let status = this.getStatusCode(exception);\n\n let finalErrors = errors;\n let finalMessage = message;\n\n if (exception instanceof NotFoundException) {\n const exceptionResponse = exception.getResponse();\n if (\n typeof exceptionResponse === 'object' &&\n exceptionResponse !== null &&\n 'message' in exceptionResponse\n ) {\n const msg = exceptionResponse.message;\n if (typeof msg === 'string' && msg.includes('Cannot')) {\n status = HttpStatus.NOT_FOUND;\n finalMessage = 'Route Not Found';\n finalErrors = [\n {\n path: 'route',\n message: [msg],\n },\n ];\n }\n }\n }\n\n const errorResponse: ErrorResponse = {\n success: false,\n message: finalMessage,\n errorMessages: finalErrors,\n };\n\n if (this.config.enableLogging) {\n this.logError(request, status, finalErrors, exception);\n }\n\n response.status(status).json(errorResponse);\n }\n\n private getStatusCode(exception: unknown): number {\n if (exception instanceof HttpException) {\n return exception.getStatus();\n }\n return HttpStatus.INTERNAL_SERVER_ERROR;\n }\n\n private logError(\n request: Request,\n status: number,\n errorMessages: ErrorMessage[],\n exception: unknown,\n ): void {\n const method = request.method;\n const url = request.url;\n const timestamp = new Date().toISOString();\n\n const logData = {\n timestamp,\n method,\n url,\n status,\n errorMessages,\n stack: this.config.hideStackTrace ? undefined : (exception as Error)?.stack,\n };\n\n this.logger.error(`${method} ${url} - ${status}`, JSON.stringify(logData));\n }\n}\n","import { Injectable } from '@nestjs/common';\nimport { ExceptionFormatter } from '../interfaces/exception-formatter.interface';\nimport { ErrorMessage } from '../interfaces/error-message.interface';\nimport { PrismaExceptionFormatter } from '../formatters/prisma-exception.formatter';\nimport { HttpExceptionFormatter } from '../formatters/http-exception.formatter';\nimport { DtoExceptionFormatter } from '../formatters/dto-exception.formatter';\nimport { UnknownExceptionFormatter } from '../formatters/unknown-exception.formatter';\n\n@Injectable()\nexport class ExceptionHandlerService {\n private formatters: ExceptionFormatter[] = [];\n private defaultFormatter: ExceptionFormatter;\n\n constructor() {\n this.defaultFormatter = new UnknownExceptionFormatter();\n this.registerFormatters();\n }\n\n private registerFormatters(): void {\n this.formatters = [\n new PrismaExceptionFormatter(),\n new HttpExceptionFormatter(),\n new DtoExceptionFormatter(),\n ];\n }\n\n registerFormatter(formatter: ExceptionFormatter): void {\n this.formatters.push(formatter);\n }\n\n getFormatter(exception: unknown): ExceptionFormatter {\n for (const formatter of this.formatters) {\n if (formatter.supports(exception)) {\n return formatter;\n }\n }\n return this.defaultFormatter;\n }\n\n formatException(exception: unknown): { errors: ErrorMessage[]; message: string } {\n const formatter = this.getFormatter(exception);\n const errors = formatter.format(exception);\n const message = formatter.message(exception);\n\n return { errors, message };\n }\n\n formatErrors(exception: unknown): ErrorMessage[] {\n const formatter = this.getFormatter(exception);\n return formatter.format(exception);\n }\n\n getErrorMessage(exception: unknown): string {\n const formatter = this.getFormatter(exception);\n return formatter.message(exception);\n }\n\n getAllFormatters(): ExceptionFormatter[] {\n return [...this.formatters];\n }\n}\n","import { HttpException } from '@nestjs/common';\nimport { ExceptionFormatter } from '../interfaces/exception-formatter.interface';\nimport { ErrorMessage } from '../interfaces/error-message.interface';\n\nexport class HttpExceptionFormatter implements ExceptionFormatter {\n supports(exception: unknown): boolean {\n return exception instanceof HttpException;\n }\n\n format(exception: unknown): ErrorMessage[] {\n const httpException = exception as HttpException;\n const response = httpException.getResponse();\n\n if (typeof response === 'string') {\n return [{ path: 'http_error', message: [response] }];\n }\n\n if (typeof response === 'object' && response !== null) {\n const responseObj = response as Record<string, unknown>;\n\n if (responseObj.message && Array.isArray(responseObj.message)) {\n return [\n {\n path: 'http_error',\n message: responseObj.message as string[],\n },\n ];\n }\n\n if (responseObj.message && typeof responseObj.message === 'string') {\n return [{ path: 'http_error', message: [responseObj.message as string] }];\n }\n\n if (responseObj.error && typeof responseObj.error === 'string') {\n return [{ path: 'http_error', message: [responseObj.error] }];\n }\n }\n\n return [{ path: 'http_error', message: ['An error occurred'] }];\n }\n\n message(exception: unknown): string {\n const httpException = exception as HttpException;\n const response = httpException.getResponse();\n\n if (typeof response === 'string') {\n return response;\n }\n\n if (typeof response === 'object' && response !== null) {\n const responseObj = response as Record<string, unknown>;\n\n if (responseObj.message && typeof responseObj.message === 'string') {\n return responseObj.message as string;\n }\n\n if (responseObj.error && typeof responseObj.error === 'string') {\n return responseObj.error as string;\n }\n }\n\n return 'An error occurred';\n }\n}\n","import { ValidationError } from '@nestjs/common';\nimport { ExceptionFormatter } from '../interfaces/exception-formatter.interface';\nimport { ErrorMessage } from '../interfaces/error-message.interface';\n\nexport class DtoExceptionFormatter implements ExceptionFormatter {\n supports(exception: unknown): boolean {\n if (!exception || typeof exception !== 'object') {\n return false;\n }\n\n const error = exception as Record<string, unknown>;\n return (\n Array.isArray(error.validationErrors) ||\n (Array.isArray(error.children) && error.constraints !== undefined)\n );\n }\n\n format(exception: unknown): ErrorMessage[] {\n const error = exception as Record<string, unknown>;\n const validationErrors = error.validationErrors as ValidationError[] | undefined;\n const children = error.children as ValidationError[] | undefined;\n\n if (validationErrors) {\n return this.formatValidationErrors(validationErrors);\n }\n\n if (children) {\n return this.formatChildrenErrors(children);\n }\n\n return [{ path: 'unknown', message: ['Validation failed'] }];\n }\n\n message(exception: unknown): string {\n const error = exception as Record<string, unknown>;\n const validationErrors = error.validationErrors as ValidationError[] | undefined;\n const children = error.children as ValidationError[] | undefined;\n\n if (validationErrors && validationErrors.length > 0) {\n const firstError = validationErrors[0];\n const constraints = firstError.constraints;\n if (constraints) {\n return Object.values(constraints)[0];\n }\n }\n\n if (children && children.length > 0) {\n return 'Validation failed for nested fields';\n }\n\n return 'Validation failed';\n }\n\n private formatValidationErrors(errors: ValidationError[]): ErrorMessage[] {\n return errors.flatMap((error) => {\n const constraints = error.constraints;\n if (constraints) {\n return [\n {\n path: error.property,\n message: Object.values(constraints),\n },\n ];\n }\n return [];\n });\n }\n\n private formatChildrenErrors(children: ValidationError[]): ErrorMessage[] {\n return children.flatMap((child) => {\n const constraints = child.constraints;\n if (constraints) {\n return [\n {\n path: child.property,\n message: Object.values(constraints),\n },\n ];\n }\n return [];\n });\n }\n}\n","export const DEFAULT_ERROR_MESSAGES = {\n UNKNOWN_ERROR: 'An unexpected error occurred',\n VALIDATION_ERROR: 'Validation failed',\n DATABASE_ERROR: 'Database error',\n NOT_FOUND: 'Resource not found',\n UNAUTHORIZED: 'Unauthorized access',\n FORBIDDEN: 'Access forbidden',\n CONFLICT: 'Conflict occurred',\n BAD_REQUEST: 'Bad request',\n};\n\nexport const PRISMA_ERROR_MESSAGES: Record<string, string> = {\n P2002: 'A record with this {field} already exists.',\n P2003: 'This {field} does not exist.',\n P2005: 'Invalid value for {field}.',\n P2006: 'Invalid format for {field}.',\n P2025: 'Record not found.',\n};\n\nexport const DEFAULT_PATH = 'unknown';\n","import { ExceptionFormatter } from '../interfaces/exception-formatter.interface';\nimport { ErrorMessage } from '../interfaces/error-message.interface';\nimport { DEFAULT_PATH } from '../constants/default-messages';\n\nexport class UnknownExceptionFormatter implements ExceptionFormatter {\n supports(_exception: unknown): boolean {\n return true;\n }\n\n format(_exception: unknown): ErrorMessage[] {\n return [\n {\n path: DEFAULT_PATH,\n message: ['Something went wrong'],\n },\n ];\n }\n\n message(_exception: unknown): string {\n return 'Internal Server Error';\n }\n}\n","import { DynamicModule, Module } from '@nestjs/common';\nimport { ExceptionHandlerService } from '../services/exception-handler.service';\nimport { GlobalExceptionFilter } from '../filter/global-exception.filter';\nimport { ExceptionHandlerConfig } from '../interfaces/exception-handler-config.interface';\nimport { PrismaExceptionFormatter } from '../formatters/prisma-exception.formatter';\nimport { DtoExceptionFormatter } from '../formatters/dto-exception.formatter';\nimport { HttpExceptionFormatter } from '../formatters/http-exception.formatter';\nimport { UnknownExceptionFormatter } from '../formatters/unknown-exception.formatter';\n\n@Module({})\nexport class ExceptionHandlerModule {\n static forRoot(config?: ExceptionHandlerConfig): DynamicModule {\n const providers = [\n ExceptionHandlerService,\n {\n provide: GlobalExceptionFilter,\n useFactory: (service: ExceptionHandlerService) => {\n return new GlobalExceptionFilter(service, config);\n },\n inject: [ExceptionHandlerService],\n },\n ];\n\n return {\n module: ExceptionHandlerModule,\n providers,\n exports: [ExceptionHandlerService, GlobalExceptionFilter],\n global: true,\n };\n }\n\n static forFeature(config?: ExceptionHandlerConfig): DynamicModule {\n return this.forRoot(config);\n }\n}\n\n// Initialize formatters\nexport function initializeFormatters(service: ExceptionHandlerService): void {\n service.registerFormatter(new PrismaExceptionFormatter());\n service.registerFormatter(new DtoExceptionFormatter());\n service.registerFormatter(new HttpExceptionFormatter());\n service.registerFormatter(new UnknownExceptionFormatter());\n}\n","import { HttpException } from '@nestjs/common';\nimport { ErrorMessage } from '../interfaces/error-message.interface';\n\nexport class HttpErrorFormatter {\n formatHttpException(exception: HttpException): ErrorMessage[] {\n const response = exception.getResponse();\n\n if (typeof response === 'string') {\n return [{ path: 'http_error', message: [response] }];\n }\n\n if (typeof response === 'object' && response !== null) {\n const responseObj = response as Record<string, unknown>;\n\n if (Array.isArray(responseObj.message)) {\n return [\n {\n path: 'http_error',\n message: responseObj.message as string[],\n },\n ];\n }\n\n if (typeof responseObj.message === 'string') {\n return [{ path: 'http_error', message: [responseObj.message] }];\n }\n\n if (responseObj.error && typeof responseObj.error === 'string') {\n return [{ path: 'http_error', message: [responseObj.error] }];\n }\n }\n\n return [{ path: 'http_error', message: ['An error occurred'] }];\n }\n\n getMessage(exception: HttpException): string {\n const response = exception.getResponse();\n\n if (typeof response === 'string') {\n return response;\n }\n\n if (typeof response === 'object' && response !== null) {\n const responseObj = response as Record<string, unknown>;\n\n if (typeof responseObj.message === 'string') {\n return responseObj.message;\n }\n\n if (responseObj.error && typeof responseObj.error === 'string') {\n return response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,MAChE;AAEA,UAAI,YAAY,SAAS,OAAO,YAAY,UAAU,UAAU;AAC9D,eAAO,CAAC,EAAE,MAAM,cAAc,SAAS,CAAC,YAAY,KAAK,EAAE,CAAC;AAAA,MAC9D;AAAA,IACF;AAEA,WAAO,CAAC,EAAE,MAAM,cAAc,SAAS,CAAC,mBAAmB,EAAE,CAAC;AAAA,EAChE;AAAA,EAEA,WAAW,WAAkC;AAC3C,UAAM,WAAW,UAAU,YAAY;AAEvC,QAAI,OAAO,aAAa,UAAU;AAChC,aAAO;AAAA,IACT;AAEA,QAAI,OAAO,aAAa,YAAY,aAAa,MAAM;AACrD,YAAM,cAAc;AAEpB,UAAI,OAAO,YAAY,YAAY,UAAU;AAC3C,eAAO,YAAY;AAAA,MACrB;AAEA,UAAI,YAAY,SAAS,OAAO,YAAY,UAAU,UAAU;AAC9D,eAAO,YAAY;AAAA,MACrB;AAAA,IACF;AAEA,WAAO;AAAA,EACT;AACF;","names":["import_common","import_common","import_common","import_common","import_common"]}
1
+ {"version":3,"sources":["../src/index.ts","../src/formatters/validation-error.formatter.ts","../src/formatters/prisma-exception.formatter.ts","../src/formatters/dto-validation.formatter.ts","../src/filter/global-exception.filter.ts","../src/services/exception-handler.service.ts","../src/formatters/http-exception.formatter.ts","../src/formatters/dto-exception.formatter.ts","../src/constants/default-messages.ts","../src/formatters/unknown-exception.formatter.ts","../src/module/exception-handler.module.ts","../src/utils/http-error.formatter.ts"],"sourcesContent":["export * from './interfaces';\nexport * from './formatters/validation-error.formatter';\nexport * from './formatters/prisma-exception.formatter';\nexport * from './formatters/dto-validation.formatter';\nexport * from './filter/global-exception.filter';\nexport * from './module/exception-handler.module';\nexport * from './services/exception-handler.service';\nexport * from './utils/http-error.formatter';\n","import { HttpException, ValidationError } from '@nestjs/common';\nimport { ErrorMessage } from '../interfaces/error-message.interface';\n\nexport class ValidationErrorFormatter {\n formatValidationErrors(exception: HttpException): ErrorMessage[] {\n const response = exception.getResponse();\n\n if (typeof response === 'object' && response !== null) {\n const responseObj = response as Record<string, unknown>;\n\n if (Array.isArray(responseObj.message)) {\n const messages = responseObj.message;\n\n if (messages.length > 0 && typeof messages[0] === 'object' && 'property' in messages[0]) {\n return this.formatNestedValidationErrors(messages as ValidationError[]);\n }\n\n return [\n {\n path: 'http_error',\n message: messages as string[],\n },\n ];\n }\n }\n\n return [\n {\n path: 'http_error',\n message: ['Validation failed'],\n },\n ];\n }\n\n private formatNestedValidationErrors(errors: ValidationError[]): ErrorMessage[] {\n return errors.map((error) => ({\n path: error.property,\n message: error.constraints ? Object.values(error.constraints) : ['Validation error'],\n }));\n }\n}\n","import { Injectable } from '@nestjs/common';\nimport { ErrorMessage } from '../interfaces/error-message.interface';\nimport { ExceptionFormatter } from '../interfaces/exception-formatter.interface';\n\ninterface PrismaError {\n code?: string;\n meta?: Record<string, unknown>;\n message?: string;\n clientVersion?: string;\n}\n\n@Injectable()\nexport class PrismaExceptionFormatter implements ExceptionFormatter {\n supports(exception: unknown): boolean {\n if (!exception || typeof exception !== 'object') {\n return false;\n }\n\n const error = exception as Record<string, unknown>;\n const hasErrorCode = typeof error.code === 'string';\n const hasClientVersion = typeof error.clientVersion === 'string';\n const hasMeta = typeof error.meta === 'object';\n\n return hasErrorCode || (hasClientVersion && hasMeta);\n }\n\n format(exception: unknown): ErrorMessage[] {\n return this.formatError(exception as PrismaError);\n }\n\n message(_exception: unknown): string {\n return 'Database error';\n }\n\n formatError(exception: PrismaError): ErrorMessage[] {\n const code = exception.code;\n\n if (code) {\n return this.formatPrismaError(exception);\n }\n\n const message = exception.message || '';\n if (message.includes('validation') || message.includes('Rust') || message.includes('panic')) {\n return this.formatQueryError(exception);\n }\n\n if (message.includes('initialization') || message.includes('connect')) {\n return this.formatInitializationError(exception);\n }\n\n return this.formatUnknownError(exception);\n }\n\n private formatPrismaError(exception: PrismaError): ErrorMessage[] {\n const code = exception.code;\n const meta = exception.meta;\n\n switch (code) {\n case 'P2002': {\n const target = meta?.target as string[] | undefined;\n const field = target?.[0] || 'field';\n return [\n {\n path: field,\n message: [`A record with this ${field} already exists.`],\n },\n ];\n }\n case 'P2003': {\n const fieldName = meta?.field_name as string | undefined;\n return [\n {\n path: fieldName || 'field',\n message: [`The referenced ${fieldName || 'record'} does not exist.`],\n },\n ];\n }\n case 'P2005': {\n const fieldName = meta?.field_name as string | undefined;\n return [\n {\n path: fieldName || 'field',\n message: [`The value for ${fieldName || 'field'} is invalid.`],\n },\n ];\n }\n case 'P2006': {\n const fieldName = meta?.field_name as string | undefined;\n return [\n {\n path: fieldName || 'field',\n message: [`The ${fieldName || 'field'} field is required.`],\n },\n ];\n }\n case 'P2025': {\n return [\n {\n path: 'record',\n message: ['The requested record does not exist.'],\n },\n ];\n }\n default:\n return [\n {\n path: 'database',\n message: ['Database operation failed.'],\n },\n ];\n }\n }\n\n private formatQueryError(exception: PrismaError): ErrorMessage[] {\n const message = exception.message || '';\n let errorMessage = 'Invalid database query.';\n\n if (message.includes('panic')) {\n errorMessage = 'Database engine panic occurred.';\n }\n\n return [\n {\n path: 'database',\n message: [errorMessage],\n },\n ];\n }\n\n private formatInitializationError(exception: PrismaError): ErrorMessage[] {\n return [\n {\n path: 'database',\n message: [`Database initialization error: ${exception.message || 'Unknown error'}`],\n },\n ];\n }\n\n private formatUnknownError(exception: unknown): ErrorMessage[] {\n return [\n {\n path: 'unknown',\n message:\n exception instanceof Error\n ? [exception.message]\n : ['An unexpected database error occurred.'],\n },\n ];\n }\n}\n","import { Injectable } from '@nestjs/common';\nimport { HttpException } from '@nestjs/common';\nimport { ErrorMessage } from '../interfaces/error-message.interface';\n\ninterface ValidationError {\n property: string;\n constraints?: Record<string, string>;\n children?: ValidationError[];\n}\n\n@Injectable()\nexport class DtoValidationFormatter {\n formatDtoValidationException(exception: HttpException): ErrorMessage[] {\n const responseBody: unknown = exception.getResponse();\n\n if (\n typeof responseBody === 'object' &&\n responseBody !== null &&\n 'message' in responseBody &&\n Array.isArray((responseBody as Record<string, unknown>).message)\n ) {\n const messages = (responseBody as Record<string, unknown>).message as unknown[];\n const firstMessage = messages[0];\n\n if (\n firstMessage &&\n typeof firstMessage === 'object' &&\n firstMessage !== null &&\n 'property' in firstMessage\n ) {\n const validationErrors = messages as ValidationError[];\n return validationErrors.map((error: ValidationError) => ({\n path: error.property,\n message: error.constraints ? Object.values(error.constraints) : ['Validation error'],\n }));\n }\n\n if (typeof firstMessage === 'string') {\n return [\n {\n path: 'http_error',\n message: messages as string[],\n },\n ];\n }\n }\n\n return [\n {\n path: 'http_error',\n message:\n typeof responseBody === 'object' && responseBody !== null && 'message' in responseBody\n ? [(responseBody as Record<string, unknown>).message as string]\n : ['An HTTP error occurred'],\n },\n ];\n }\n}\n","import {\n ExceptionFilter,\n Catch,\n ArgumentsHost,\n HttpException,\n HttpStatus,\n Logger,\n NotFoundException,\n} from '@nestjs/common';\nimport { Request, Response } from 'express';\nimport { ExceptionHandlerService } from '../services/exception-handler.service';\nimport { ErrorResponse, ErrorMessage } from '../interfaces/error-message.interface';\nimport { ExceptionHandlerConfig } from '../interfaces/exception-handler-config.interface';\n\n@Catch()\nexport class GlobalExceptionFilter implements ExceptionFilter {\n private readonly logger = new Logger(GlobalExceptionFilter.name);\n private config: ExceptionHandlerConfig;\n\n constructor(\n private exceptionHandlerService?: ExceptionHandlerService,\n config?: ExceptionHandlerConfig,\n ) {\n this.config = config || { enableLogging: true, hideStackTrace: false };\n }\n\n private getService(): ExceptionHandlerService {\n if (!this.exceptionHandlerService) {\n this.exceptionHandlerService = new ExceptionHandlerService();\n }\n return this.exceptionHandlerService;\n }\n\n catch(exception: unknown, host: ArgumentsHost): void {\n const ctx = host.switchToHttp();\n const response = ctx.getResponse<Response>();\n const request = ctx.getRequest<Request>();\n\n const { errors, message } = this.getService().formatException(exception);\n let status = this.getStatusCode(exception);\n\n let finalErrors = errors;\n let finalMessage = message;\n\n if (exception instanceof NotFoundException) {\n const exceptionResponse = exception.getResponse();\n if (\n typeof exceptionResponse === 'object' &&\n exceptionResponse !== null &&\n 'message' in exceptionResponse\n ) {\n const msg = exceptionResponse.message;\n if (typeof msg === 'string' && msg.includes('Cannot')) {\n status = HttpStatus.NOT_FOUND;\n finalMessage = 'Route Not Found';\n finalErrors = [\n {\n path: 'route',\n message: [msg],\n },\n ];\n }\n }\n }\n\n const errorResponse: ErrorResponse = {\n success: false,\n message: finalMessage,\n errorMessages: finalErrors,\n };\n\n if (this.config.enableLogging) {\n this.logError(request, status, finalErrors, exception);\n }\n\n response.status(status).json(errorResponse);\n }\n\n private getStatusCode(exception: unknown): number {\n if (exception instanceof HttpException) {\n return exception.getStatus();\n }\n return HttpStatus.INTERNAL_SERVER_ERROR;\n }\n\n private logError(\n request: Request,\n status: number,\n errorMessages: ErrorMessage[],\n exception: unknown,\n ): void {\n const method = request.method;\n const url = request.url;\n const timestamp = new Date().toISOString();\n\n const logData = {\n timestamp,\n method,\n url,\n status,\n errorMessages,\n stack: this.config.hideStackTrace ? undefined : (exception as Error)?.stack,\n };\n\n this.logger.error(`${method} ${url} - ${status}`, JSON.stringify(logData));\n }\n}\n","import { Injectable } from '@nestjs/common';\nimport { ExceptionFormatter } from '../interfaces/exception-formatter.interface';\nimport { ErrorMessage } from '../interfaces/error-message.interface';\nimport { PrismaExceptionFormatter } from '../formatters/prisma-exception.formatter';\nimport { HttpExceptionFormatter } from '../formatters/http-exception.formatter';\nimport { DtoExceptionFormatter } from '../formatters/dto-exception.formatter';\nimport { UnknownExceptionFormatter } from '../formatters/unknown-exception.formatter';\n\n@Injectable()\nexport class ExceptionHandlerService {\n private formatters: ExceptionFormatter[] = [];\n private defaultFormatter: ExceptionFormatter;\n\n constructor() {\n this.defaultFormatter = new UnknownExceptionFormatter();\n this.registerFormatters();\n }\n\n private registerFormatters(): void {\n this.formatters = [\n new PrismaExceptionFormatter(),\n new HttpExceptionFormatter(),\n new DtoExceptionFormatter(),\n ];\n }\n\n registerFormatter(formatter: ExceptionFormatter): void {\n this.formatters.push(formatter);\n }\n\n getFormatter(exception: unknown): ExceptionFormatter {\n for (const formatter of this.formatters) {\n if (formatter.supports(exception)) {\n return formatter;\n }\n }\n return this.defaultFormatter;\n }\n\n formatException(exception: unknown): { errors: ErrorMessage[]; message: string } {\n const formatter = this.getFormatter(exception);\n const errors = formatter.format(exception);\n const message = formatter.message(exception);\n\n return { errors, message };\n }\n\n formatErrors(exception: unknown): ErrorMessage[] {\n const formatter = this.getFormatter(exception);\n return formatter.format(exception);\n }\n\n getErrorMessage(exception: unknown): string {\n const formatter = this.getFormatter(exception);\n return formatter.message(exception);\n }\n\n getAllFormatters(): ExceptionFormatter[] {\n return [...this.formatters];\n }\n}\n","import { HttpException } from '@nestjs/common';\nimport { ExceptionFormatter } from '../interfaces/exception-formatter.interface';\nimport { ErrorMessage } from '../interfaces/error-message.interface';\n\nexport class HttpExceptionFormatter implements ExceptionFormatter {\n supports(exception: unknown): boolean {\n return exception instanceof HttpException;\n }\n\n format(exception: unknown): ErrorMessage[] {\n const httpException = exception as HttpException;\n const response = httpException.getResponse();\n\n if (typeof response === 'string') {\n return [{ path: 'http_error', message: [response] }];\n }\n\n if (typeof response === 'object' && response !== null) {\n const responseObj = response as Record<string, unknown>;\n\n if (responseObj.message && Array.isArray(responseObj.message)) {\n return [\n {\n path: 'http_error',\n message: responseObj.message as string[],\n },\n ];\n }\n\n if (responseObj.message && typeof responseObj.message === 'string') {\n return [{ path: 'http_error', message: [responseObj.message as string] }];\n }\n\n if (responseObj.error && typeof responseObj.error === 'string') {\n return [{ path: 'http_error', message: [responseObj.error] }];\n }\n }\n\n return [{ path: 'http_error', message: ['An error occurred'] }];\n }\n\n message(exception: unknown): string {\n const httpException = exception as HttpException;\n const response = httpException.getResponse();\n\n if (typeof response === 'string') {\n return response;\n }\n\n if (typeof response === 'object' && response !== null) {\n const responseObj = response as Record<string, unknown>;\n\n if (responseObj.message && typeof responseObj.message === 'string') {\n return responseObj.message as string;\n }\n\n if (responseObj.error && typeof responseObj.error === 'string') {\n return responseObj.error as string;\n }\n }\n\n return 'An error occurred';\n }\n}\n","import { ValidationError } from '@nestjs/common';\nimport { ExceptionFormatter } from '../interfaces/exception-formatter.interface';\nimport { ErrorMessage } from '../interfaces/error-message.interface';\n\nexport class DtoExceptionFormatter implements ExceptionFormatter {\n supports(exception: unknown): boolean {\n if (!exception || typeof exception !== 'object') {\n return false;\n }\n\n const error = exception as Record<string, unknown>;\n return (\n Array.isArray(error.validationErrors) ||\n (Array.isArray(error.children) && error.constraints !== undefined)\n );\n }\n\n format(exception: unknown): ErrorMessage[] {\n const error = exception as Record<string, unknown>;\n const validationErrors = error.validationErrors as ValidationError[] | undefined;\n const children = error.children as ValidationError[] | undefined;\n\n if (validationErrors) {\n return this.formatValidationErrors(validationErrors);\n }\n\n if (children) {\n return this.formatChildrenErrors(children);\n }\n\n return [{ path: 'unknown', message: ['Validation failed'] }];\n }\n\n message(exception: unknown): string {\n const error = exception as Record<string, unknown>;\n const validationErrors = error.validationErrors as ValidationError[] | undefined;\n const children = error.children as ValidationError[] | undefined;\n\n if (validationErrors && validationErrors.length > 0) {\n const firstError = validationErrors[0];\n const constraints = firstError.constraints;\n if (constraints) {\n return Object.values(constraints)[0];\n }\n }\n\n if (children && children.length > 0) {\n return 'Validation failed for nested fields';\n }\n\n return 'Validation failed';\n }\n\n private formatValidationErrors(errors: ValidationError[]): ErrorMessage[] {\n return errors.flatMap((error) => {\n const constraints = error.constraints;\n if (constraints) {\n return [\n {\n path: error.property,\n message: Object.values(constraints),\n },\n ];\n }\n return [];\n });\n }\n\n private formatChildrenErrors(children: ValidationError[]): ErrorMessage[] {\n return children.flatMap((child) => {\n const constraints = child.constraints;\n if (constraints) {\n return [\n {\n path: child.property,\n message: Object.values(constraints),\n },\n ];\n }\n return [];\n });\n }\n}\n","export const DEFAULT_ERROR_MESSAGES = {\n UNKNOWN_ERROR: 'An unexpected error occurred',\n VALIDATION_ERROR: 'Validation failed',\n DATABASE_ERROR: 'Database error',\n NOT_FOUND: 'Resource not found',\n UNAUTHORIZED: 'Unauthorized access',\n FORBIDDEN: 'Access forbidden',\n CONFLICT: 'Conflict occurred',\n BAD_REQUEST: 'Bad request',\n};\n\nexport const PRISMA_ERROR_MESSAGES: Record<string, string> = {\n P2002: 'A record with this {field} already exists.',\n P2003: 'This {field} does not exist.',\n P2005: 'Invalid value for {field}.',\n P2006: 'Invalid format for {field}.',\n P2025: 'Record not found.',\n};\n\nexport const DEFAULT_PATH = 'unknown';\n","import { ExceptionFormatter } from '../interfaces/exception-formatter.interface';\nimport { ErrorMessage } from '../interfaces/error-message.interface';\nimport { DEFAULT_PATH } from '../constants/default-messages';\n\nexport class UnknownExceptionFormatter implements ExceptionFormatter {\n supports(_exception: unknown): boolean {\n return true;\n }\n\n format(_exception: unknown): ErrorMessage[] {\n return [\n {\n path: DEFAULT_PATH,\n message: ['Something went wrong'],\n },\n ];\n }\n\n message(_exception: unknown): string {\n return 'Internal Server Error';\n }\n}\n","import { DynamicModule, Module } from '@nestjs/common';\nimport { ExceptionHandlerService } from '../services/exception-handler.service';\nimport { GlobalExceptionFilter } from '../filter/global-exception.filter';\nimport { ExceptionHandlerConfig } from '../interfaces/exception-handler-config.interface';\nimport { PrismaExceptionFormatter } from '../formatters/prisma-exception.formatter';\nimport { DtoExceptionFormatter } from '../formatters/dto-exception.formatter';\nimport { HttpExceptionFormatter } from '../formatters/http-exception.formatter';\nimport { UnknownExceptionFormatter } from '../formatters/unknown-exception.formatter';\n\n@Module({})\nexport class ExceptionHandlerModule {\n static forRoot(config?: ExceptionHandlerConfig): DynamicModule {\n const providers = [\n ExceptionHandlerService,\n {\n provide: GlobalExceptionFilter,\n useFactory: (service: ExceptionHandlerService) => {\n return new GlobalExceptionFilter(service, config);\n },\n inject: [ExceptionHandlerService],\n },\n ];\n\n return {\n module: ExceptionHandlerModule,\n providers,\n exports: [ExceptionHandlerService, GlobalExceptionFilter],\n global: true,\n };\n }\n\n static forFeature(config?: ExceptionHandlerConfig): DynamicModule {\n return this.forRoot(config);\n }\n}\n\n// Initialize formatters\nexport function initializeFormatters(service: ExceptionHandlerService): void {\n service.registerFormatter(new PrismaExceptionFormatter());\n service.registerFormatter(new DtoExceptionFormatter());\n service.registerFormatter(new HttpExceptionFormatter());\n service.registerFormatter(new UnknownExceptionFormatter());\n}\n","import { HttpException } from '@nestjs/common';\nimport { ErrorMessage } from '../interfaces/error-message.interface';\n\nexport class HttpErrorFormatter {\n formatHttpException(exception: HttpException): ErrorMessage[] {\n const response = exception.getResponse();\n\n if (typeof response === 'string') {\n return [{ path: 'http_error', message: [response] }];\n }\n\n if (typeof response === 'object' && response !== null) {\n const responseObj = response as Record<string, unknown>;\n\n if (Array.isArray(responseObj.message)) {\n return [\n {\n path: 'http_error',\n message: responseObj.message as string[],\n },\n ];\n }\n\n if (typeof responseObj.message === 'string') {\n return [{ path: 'http_error', message: [responseObj.message] }];\n }\n\n if (responseObj.error && typeof responseObj.error === 'string') {\n return [{ path: 'http_error', message: [responseObj.error] }];\n }\n }\n\n return [{ path: 'http_error', message: ['An error occurred'] }];\n }\n\n getMessage(exception: HttpException): string {\n const response = exception.getResponse();\n\n if (typeof response === 'string') {\n return response;\n }\n\n if (typeof response === 'object' && response !== null) {\n const responseObj = response as Record<string, unknown>;\n\n if (typeof responseObj.message === 'string') {\n return responseObj.message;\n }\n\n if (responseObj.error && typeof responseObj.error === 'string') {\n return responseObj.error;\n }\n }\n\n return 'An error occurred';\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACGO,IAAM,2BAAN,MAA+B;AAAA,EACpC,uBAAuB,WAA0C;AAC/D,UAAM,WAAW,UAAU,YAAY;AAEvC,QAAI,OAAO,aAAa,YAAY,aAAa,MAAM;AACrD,YAAM,cAAc;AAEpB,UAAI,MAAM,QAAQ,YAAY,OAAO,GAAG;AACtC,cAAM,WAAW,YAAY;AAE7B,YAAI,SAAS,SAAS,KAAK,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AAE,MAAM,cAAc,SAAS,CAAC,YAAY,KAAK,EAAE,CAAC;AAAA,MAC9D;AAAA,IACF;AAEA,WAAO,CAAC,EAAE,MAAM,cAAc,SAAS,CAAC,mBAAmB,EAAE,CAAC;AAAA,EAChE;AAAA,EAEA,WAAW,WAAkC;AAC3C,UAAM,WAAW,UAAU,YAAY;AAEvC,QAAI,OAAO,aAAa,UAAU;AAChC,aAAO;AAAA,IACT;AAEA,QAAI,OAAO,aAAa,YAAY,aAAa,MAAM;AACrD,YAAM,cAAc;AAEpB,UAAI,OAAO,YAAY,YAAY,UAAU;AAC3C,eAAO,YAAY;AAAA,MACrB;AAEA,UAAI,YAAY,SAAS,OAAO,YAAY,UAAU,UAAU;AAC9D,eAAO,YAAY;AAAA,MACrB;AAAA,IACF;AAEA,WAAO;AAAA,EACT;AACF;","names":["import_common","import_common","import_common","import_common","import_common"]}
package/dist/index.mjs CHANGED
@@ -46,15 +46,16 @@ var ValidationErrorFormatter = class {
46
46
 
47
47
  // src/formatters/prisma-exception.formatter.ts
48
48
  import { Injectable } from "@nestjs/common";
49
- import {
50
- PrismaClientKnownRequestError,
51
- PrismaClientValidationError,
52
- PrismaClientRustPanicError,
53
- PrismaClientInitializationError
54
- } from "@prisma/client/runtime/library";
55
49
  var PrismaExceptionFormatter = class {
56
50
  supports(exception) {
57
- return exception instanceof PrismaClientKnownRequestError || exception instanceof PrismaClientValidationError || exception instanceof PrismaClientRustPanicError || exception instanceof PrismaClientInitializationError;
51
+ if (!exception || typeof exception !== "object") {
52
+ return false;
53
+ }
54
+ const error = exception;
55
+ const hasErrorCode = typeof error.code === "string";
56
+ const hasClientVersion = typeof error.clientVersion === "string";
57
+ const hasMeta = typeof error.meta === "object";
58
+ return hasErrorCode || hasClientVersion && hasMeta;
58
59
  }
59
60
  format(exception) {
60
61
  return this.formatError(exception);
@@ -63,13 +64,15 @@ var PrismaExceptionFormatter = class {
63
64
  return "Database error";
64
65
  }
65
66
  formatError(exception) {
66
- if (exception instanceof PrismaClientKnownRequestError) {
67
+ const code = exception.code;
68
+ if (code) {
67
69
  return this.formatPrismaError(exception);
68
70
  }
69
- if (exception instanceof PrismaClientValidationError || exception instanceof PrismaClientRustPanicError) {
71
+ const message = exception.message || "";
72
+ if (message.includes("validation") || message.includes("Rust") || message.includes("panic")) {
70
73
  return this.formatQueryError(exception);
71
74
  }
72
- if (exception instanceof PrismaClientInitializationError) {
75
+ if (message.includes("initialization") || message.includes("connect")) {
73
76
  return this.formatInitializationError(exception);
74
77
  }
75
78
  return this.formatUnknownError(exception);
@@ -133,14 +136,15 @@ var PrismaExceptionFormatter = class {
133
136
  }
134
137
  }
135
138
  formatQueryError(exception) {
136
- let message = "Invalid database query.";
137
- if (exception instanceof PrismaClientRustPanicError) {
138
- message = "Database engine panic occurred.";
139
+ const message = exception.message || "";
140
+ let errorMessage = "Invalid database query.";
141
+ if (message.includes("panic")) {
142
+ errorMessage = "Database engine panic occurred.";
139
143
  }
140
144
  return [
141
145
  {
142
146
  path: "database",
143
- message: [message]
147
+ message: [errorMessage]
144
148
  }
145
149
  ];
146
150
  }
@@ -148,7 +152,7 @@ var PrismaExceptionFormatter = class {
148
152
  return [
149
153
  {
150
154
  path: "database",
151
- message: [`Database initialization error: ${exception.message}`]
155
+ message: [`Database initialization error: ${exception.message || "Unknown error"}`]
152
156
  }
153
157
  ];
154
158
  }
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/formatters/validation-error.formatter.ts","../src/formatters/prisma-exception.formatter.ts","../src/formatters/dto-validation.formatter.ts","../src/filter/global-exception.filter.ts","../src/services/exception-handler.service.ts","../src/formatters/http-exception.formatter.ts","../src/formatters/dto-exception.formatter.ts","../src/constants/default-messages.ts","../src/formatters/unknown-exception.formatter.ts","../src/module/exception-handler.module.ts","../src/utils/http-error.formatter.ts"],"sourcesContent":["import { HttpException, ValidationError } from '@nestjs/common';\nimport { ErrorMessage } from '../interfaces/error-message.interface';\n\nexport class ValidationErrorFormatter {\n formatValidationErrors(exception: HttpException): ErrorMessage[] {\n const response = exception.getResponse();\n\n if (typeof response === 'object' && response !== null) {\n const responseObj = response as Record<string, unknown>;\n\n if (Array.isArray(responseObj.message)) {\n const messages = responseObj.message;\n\n if (messages.length > 0 && typeof messages[0] === 'object' && 'property' in messages[0]) {\n return this.formatNestedValidationErrors(messages as ValidationError[]);\n }\n\n return [\n {\n path: 'http_error',\n message: messages as string[],\n },\n ];\n }\n }\n\n return [\n {\n path: 'http_error',\n message: ['Validation failed'],\n },\n ];\n }\n\n private formatNestedValidationErrors(errors: ValidationError[]): ErrorMessage[] {\n return errors.map((error) => ({\n path: error.property,\n message: error.constraints ? Object.values(error.constraints) : ['Validation error'],\n }));\n }\n}\n","import { Injectable } from '@nestjs/common';\nimport {\n PrismaClientKnownRequestError,\n PrismaClientValidationError,\n PrismaClientRustPanicError,\n PrismaClientInitializationError,\n} from '@prisma/client/runtime/library';\nimport { ErrorMessage } from '../interfaces/error-message.interface';\nimport { ExceptionFormatter } from '../interfaces/exception-formatter.interface';\n\ntype PrismaError =\n | PrismaClientKnownRequestError\n | PrismaClientValidationError\n | PrismaClientRustPanicError\n | PrismaClientInitializationError\n | unknown;\n\n@Injectable()\nexport class PrismaExceptionFormatter implements ExceptionFormatter {\n supports(exception: unknown): boolean {\n return (\n exception instanceof PrismaClientKnownRequestError ||\n exception instanceof PrismaClientValidationError ||\n exception instanceof PrismaClientRustPanicError ||\n exception instanceof PrismaClientInitializationError\n );\n }\n\n format(exception: unknown): ErrorMessage[] {\n return this.formatError(exception as PrismaError);\n }\n\n message(_exception: unknown): string {\n return 'Database error';\n }\n\n formatError(exception: PrismaError): ErrorMessage[] {\n if (exception instanceof PrismaClientKnownRequestError) {\n return this.formatPrismaError(exception);\n }\n\n if (\n exception instanceof PrismaClientValidationError ||\n exception instanceof PrismaClientRustPanicError\n ) {\n return this.formatQueryError(exception);\n }\n\n if (exception instanceof PrismaClientInitializationError) {\n return this.formatInitializationError(exception);\n }\n\n return this.formatUnknownError(exception);\n }\n\n private formatPrismaError(exception: PrismaClientKnownRequestError): ErrorMessage[] {\n const code = exception.code;\n const meta = exception.meta as Record<string, unknown> | undefined;\n\n switch (code) {\n case 'P2002': {\n const target = meta?.target as string[] | undefined;\n const field = target?.[0] || 'field';\n return [\n {\n path: field,\n message: [`A record with this ${field} already exists.`],\n },\n ];\n }\n case 'P2003': {\n const fieldName = meta?.field_name as string | undefined;\n return [\n {\n path: fieldName || 'field',\n message: [`The referenced ${fieldName || 'record'} does not exist.`],\n },\n ];\n }\n case 'P2005': {\n const fieldName = meta?.field_name as string | undefined;\n return [\n {\n path: fieldName || 'field',\n message: [`The value for ${fieldName || 'field'} is invalid.`],\n },\n ];\n }\n case 'P2006': {\n const fieldName = meta?.field_name as string | undefined;\n return [\n {\n path: fieldName || 'field',\n message: [`The ${fieldName || 'field'} field is required.`],\n },\n ];\n }\n case 'P2025': {\n return [\n {\n path: 'record',\n message: ['The requested record does not exist.'],\n },\n ];\n }\n default:\n return [\n {\n path: 'database',\n message: ['Database operation failed.'],\n },\n ];\n }\n }\n\n private formatQueryError(\n exception: PrismaClientValidationError | PrismaClientRustPanicError,\n ): ErrorMessage[] {\n let message = 'Invalid database query.';\n\n if (exception instanceof PrismaClientRustPanicError) {\n message = 'Database engine panic occurred.';\n }\n\n return [\n {\n path: 'database',\n message: [message],\n },\n ];\n }\n\n private formatInitializationError(exception: PrismaClientInitializationError): ErrorMessage[] {\n return [\n {\n path: 'database',\n message: [`Database initialization error: ${exception.message}`],\n },\n ];\n }\n\n private formatUnknownError(exception: unknown): ErrorMessage[] {\n return [\n {\n path: 'unknown',\n message:\n exception instanceof Error\n ? [exception.message]\n : ['An unexpected database error occurred.'],\n },\n ];\n }\n}\n","import { Injectable } from '@nestjs/common';\nimport { HttpException } from '@nestjs/common';\nimport { ErrorMessage } from '../interfaces/error-message.interface';\n\ninterface ValidationError {\n property: string;\n constraints?: Record<string, string>;\n children?: ValidationError[];\n}\n\n@Injectable()\nexport class DtoValidationFormatter {\n formatDtoValidationException(exception: HttpException): ErrorMessage[] {\n const responseBody: unknown = exception.getResponse();\n\n if (\n typeof responseBody === 'object' &&\n responseBody !== null &&\n 'message' in responseBody &&\n Array.isArray((responseBody as Record<string, unknown>).message)\n ) {\n const messages = (responseBody as Record<string, unknown>).message as unknown[];\n const firstMessage = messages[0];\n\n if (\n firstMessage &&\n typeof firstMessage === 'object' &&\n firstMessage !== null &&\n 'property' in firstMessage\n ) {\n const validationErrors = messages as ValidationError[];\n return validationErrors.map((error: ValidationError) => ({\n path: error.property,\n message: error.constraints ? Object.values(error.constraints) : ['Validation error'],\n }));\n }\n\n if (typeof firstMessage === 'string') {\n return [\n {\n path: 'http_error',\n message: messages as string[],\n },\n ];\n }\n }\n\n return [\n {\n path: 'http_error',\n message:\n typeof responseBody === 'object' && responseBody !== null && 'message' in responseBody\n ? [(responseBody as Record<string, unknown>).message as string]\n : ['An HTTP error occurred'],\n },\n ];\n }\n}\n","import {\n ExceptionFilter,\n Catch,\n ArgumentsHost,\n HttpException,\n HttpStatus,\n Logger,\n NotFoundException,\n} from '@nestjs/common';\nimport { Request, Response } from 'express';\nimport { ExceptionHandlerService } from '../services/exception-handler.service';\nimport { ErrorResponse, ErrorMessage } from '../interfaces/error-message.interface';\nimport { ExceptionHandlerConfig } from '../interfaces/exception-handler-config.interface';\n\n@Catch()\nexport class GlobalExceptionFilter implements ExceptionFilter {\n private readonly logger = new Logger(GlobalExceptionFilter.name);\n private config: ExceptionHandlerConfig;\n\n constructor(\n private exceptionHandlerService?: ExceptionHandlerService,\n config?: ExceptionHandlerConfig,\n ) {\n this.config = config || { enableLogging: true, hideStackTrace: false };\n }\n\n private getService(): ExceptionHandlerService {\n if (!this.exceptionHandlerService) {\n this.exceptionHandlerService = new ExceptionHandlerService();\n }\n return this.exceptionHandlerService;\n }\n\n catch(exception: unknown, host: ArgumentsHost): void {\n const ctx = host.switchToHttp();\n const response = ctx.getResponse<Response>();\n const request = ctx.getRequest<Request>();\n\n const { errors, message } = this.getService().formatException(exception);\n let status = this.getStatusCode(exception);\n\n let finalErrors = errors;\n let finalMessage = message;\n\n if (exception instanceof NotFoundException) {\n const exceptionResponse = exception.getResponse();\n if (\n typeof exceptionResponse === 'object' &&\n exceptionResponse !== null &&\n 'message' in exceptionResponse\n ) {\n const msg = exceptionResponse.message;\n if (typeof msg === 'string' && msg.includes('Cannot')) {\n status = HttpStatus.NOT_FOUND;\n finalMessage = 'Route Not Found';\n finalErrors = [\n {\n path: 'route',\n message: [msg],\n },\n ];\n }\n }\n }\n\n const errorResponse: ErrorResponse = {\n success: false,\n message: finalMessage,\n errorMessages: finalErrors,\n };\n\n if (this.config.enableLogging) {\n this.logError(request, status, finalErrors, exception);\n }\n\n response.status(status).json(errorResponse);\n }\n\n private getStatusCode(exception: unknown): number {\n if (exception instanceof HttpException) {\n return exception.getStatus();\n }\n return HttpStatus.INTERNAL_SERVER_ERROR;\n }\n\n private logError(\n request: Request,\n status: number,\n errorMessages: ErrorMessage[],\n exception: unknown,\n ): void {\n const method = request.method;\n const url = request.url;\n const timestamp = new Date().toISOString();\n\n const logData = {\n timestamp,\n method,\n url,\n status,\n errorMessages,\n stack: this.config.hideStackTrace ? undefined : (exception as Error)?.stack,\n };\n\n this.logger.error(`${method} ${url} - ${status}`, JSON.stringify(logData));\n }\n}\n","import { Injectable } from '@nestjs/common';\nimport { ExceptionFormatter } from '../interfaces/exception-formatter.interface';\nimport { ErrorMessage } from '../interfaces/error-message.interface';\nimport { PrismaExceptionFormatter } from '../formatters/prisma-exception.formatter';\nimport { HttpExceptionFormatter } from '../formatters/http-exception.formatter';\nimport { DtoExceptionFormatter } from '../formatters/dto-exception.formatter';\nimport { UnknownExceptionFormatter } from '../formatters/unknown-exception.formatter';\n\n@Injectable()\nexport class ExceptionHandlerService {\n private formatters: ExceptionFormatter[] = [];\n private defaultFormatter: ExceptionFormatter;\n\n constructor() {\n this.defaultFormatter = new UnknownExceptionFormatter();\n this.registerFormatters();\n }\n\n private registerFormatters(): void {\n this.formatters = [\n new PrismaExceptionFormatter(),\n new HttpExceptionFormatter(),\n new DtoExceptionFormatter(),\n ];\n }\n\n registerFormatter(formatter: ExceptionFormatter): void {\n this.formatters.push(formatter);\n }\n\n getFormatter(exception: unknown): ExceptionFormatter {\n for (const formatter of this.formatters) {\n if (formatter.supports(exception)) {\n return formatter;\n }\n }\n return this.defaultFormatter;\n }\n\n formatException(exception: unknown): { errors: ErrorMessage[]; message: string } {\n const formatter = this.getFormatter(exception);\n const errors = formatter.format(exception);\n const message = formatter.message(exception);\n\n return { errors, message };\n }\n\n formatErrors(exception: unknown): ErrorMessage[] {\n const formatter = this.getFormatter(exception);\n return formatter.format(exception);\n }\n\n getErrorMessage(exception: unknown): string {\n const formatter = this.getFormatter(exception);\n return formatter.message(exception);\n }\n\n getAllFormatters(): ExceptionFormatter[] {\n return [...this.formatters];\n }\n}\n","import { HttpException } from '@nestjs/common';\nimport { ExceptionFormatter } from '../interfaces/exception-formatter.interface';\nimport { ErrorMessage } from '../interfaces/error-message.interface';\n\nexport class HttpExceptionFormatter implements ExceptionFormatter {\n supports(exception: unknown): boolean {\n return exception instanceof HttpException;\n }\n\n format(exception: unknown): ErrorMessage[] {\n const httpException = exception as HttpException;\n const response = httpException.getResponse();\n\n if (typeof response === 'string') {\n return [{ path: 'http_error', message: [response] }];\n }\n\n if (typeof response === 'object' && response !== null) {\n const responseObj = response as Record<string, unknown>;\n\n if (responseObj.message && Array.isArray(responseObj.message)) {\n return [\n {\n path: 'http_error',\n message: responseObj.message as string[],\n },\n ];\n }\n\n if (responseObj.message && typeof responseObj.message === 'string') {\n return [{ path: 'http_error', message: [responseObj.message as string] }];\n }\n\n if (responseObj.error && typeof responseObj.error === 'string') {\n return [{ path: 'http_error', message: [responseObj.error] }];\n }\n }\n\n return [{ path: 'http_error', message: ['An error occurred'] }];\n }\n\n message(exception: unknown): string {\n const httpException = exception as HttpException;\n const response = httpException.getResponse();\n\n if (typeof response === 'string') {\n return response;\n }\n\n if (typeof response === 'object' && response !== null) {\n const responseObj = response as Record<string, unknown>;\n\n if (responseObj.message && typeof responseObj.message === 'string') {\n return responseObj.message as string;\n }\n\n if (responseObj.error && typeof responseObj.error === 'string') {\n return responseObj.error as string;\n }\n }\n\n return 'An error occurred';\n }\n}\n","import { ValidationError } from '@nestjs/common';\nimport { ExceptionFormatter } from '../interfaces/exception-formatter.interface';\nimport { ErrorMessage } from '../interfaces/error-message.interface';\n\nexport class DtoExceptionFormatter implements ExceptionFormatter {\n supports(exception: unknown): boolean {\n if (!exception || typeof exception !== 'object') {\n return false;\n }\n\n const error = exception as Record<string, unknown>;\n return (\n Array.isArray(error.validationErrors) ||\n (Array.isArray(error.children) && error.constraints !== undefined)\n );\n }\n\n format(exception: unknown): ErrorMessage[] {\n const error = exception as Record<string, unknown>;\n const validationErrors = error.validationErrors as ValidationError[] | undefined;\n const children = error.children as ValidationError[] | undefined;\n\n if (validationErrors) {\n return this.formatValidationErrors(validationErrors);\n }\n\n if (children) {\n return this.formatChildrenErrors(children);\n }\n\n return [{ path: 'unknown', message: ['Validation failed'] }];\n }\n\n message(exception: unknown): string {\n const error = exception as Record<string, unknown>;\n const validationErrors = error.validationErrors as ValidationError[] | undefined;\n const children = error.children as ValidationError[] | undefined;\n\n if (validationErrors && validationErrors.length > 0) {\n const firstError = validationErrors[0];\n const constraints = firstError.constraints;\n if (constraints) {\n return Object.values(constraints)[0];\n }\n }\n\n if (children && children.length > 0) {\n return 'Validation failed for nested fields';\n }\n\n return 'Validation failed';\n }\n\n private formatValidationErrors(errors: ValidationError[]): ErrorMessage[] {\n return errors.flatMap((error) => {\n const constraints = error.constraints;\n if (constraints) {\n return [\n {\n path: error.property,\n message: Object.values(constraints),\n },\n ];\n }\n return [];\n });\n }\n\n private formatChildrenErrors(children: ValidationError[]): ErrorMessage[] {\n return children.flatMap((child) => {\n const constraints = child.constraints;\n if (constraints) {\n return [\n {\n path: child.property,\n message: Object.values(constraints),\n },\n ];\n }\n return [];\n });\n }\n}\n","export const DEFAULT_ERROR_MESSAGES = {\n UNKNOWN_ERROR: 'An unexpected error occurred',\n VALIDATION_ERROR: 'Validation failed',\n DATABASE_ERROR: 'Database error',\n NOT_FOUND: 'Resource not found',\n UNAUTHORIZED: 'Unauthorized access',\n FORBIDDEN: 'Access forbidden',\n CONFLICT: 'Conflict occurred',\n BAD_REQUEST: 'Bad request',\n};\n\nexport const PRISMA_ERROR_MESSAGES: Record<string, string> = {\n P2002: 'A record with this {field} already exists.',\n P2003: 'This {field} does not exist.',\n P2005: 'Invalid value for {field}.',\n P2006: 'Invalid format for {field}.',\n P2025: 'Record not found.',\n};\n\nexport const DEFAULT_PATH = 'unknown';\n","import { ExceptionFormatter } from '../interfaces/exception-formatter.interface';\nimport { ErrorMessage } from '../interfaces/error-message.interface';\nimport { DEFAULT_PATH } from '../constants/default-messages';\n\nexport class UnknownExceptionFormatter implements ExceptionFormatter {\n supports(_exception: unknown): boolean {\n return true;\n }\n\n format(_exception: unknown): ErrorMessage[] {\n return [\n {\n path: DEFAULT_PATH,\n message: ['Something went wrong'],\n },\n ];\n }\n\n message(_exception: unknown): string {\n return 'Internal Server Error';\n }\n}\n","import { DynamicModule, Module } from '@nestjs/common';\nimport { ExceptionHandlerService } from '../services/exception-handler.service';\nimport { GlobalExceptionFilter } from '../filter/global-exception.filter';\nimport { ExceptionHandlerConfig } from '../interfaces/exception-handler-config.interface';\nimport { PrismaExceptionFormatter } from '../formatters/prisma-exception.formatter';\nimport { DtoExceptionFormatter } from '../formatters/dto-exception.formatter';\nimport { HttpExceptionFormatter } from '../formatters/http-exception.formatter';\nimport { UnknownExceptionFormatter } from '../formatters/unknown-exception.formatter';\n\n@Module({})\nexport class ExceptionHandlerModule {\n static forRoot(config?: ExceptionHandlerConfig): DynamicModule {\n const providers = [\n ExceptionHandlerService,\n {\n provide: GlobalExceptionFilter,\n useFactory: (service: ExceptionHandlerService) => {\n return new GlobalExceptionFilter(service, config);\n },\n inject: [ExceptionHandlerService],\n },\n ];\n\n return {\n module: ExceptionHandlerModule,\n providers,\n exports: [ExceptionHandlerService, GlobalExceptionFilter],\n global: true,\n };\n }\n\n static forFeature(config?: ExceptionHandlerConfig): DynamicModule {\n return this.forRoot(config);\n }\n}\n\n// Initialize formatters\nexport function initializeFormatters(service: ExceptionHandlerService): void {\n service.registerFormatter(new PrismaExceptionFormatter());\n service.registerFormatter(new DtoExceptionFormatter());\n service.registerFormatter(new HttpExceptionFormatter());\n service.registerFormatter(new UnknownExceptionFormatter());\n}\n","import { HttpException } from '@nestjs/common';\nimport { ErrorMessage } from '../interfaces/error-message.interface';\n\nexport class HttpErrorFormatter {\n formatHttpException(exception: HttpException): ErrorMessage[] {\n const response = exception.getResponse();\n\n if (typeof response === 'string') {\n return [{ path: 'http_error', message: [response] }];\n }\n\n if (typeof response === 'object' && response !== null) {\n const responseObj = response as Record<string, unknown>;\n\n if (Array.isArray(responseObj.message)) {\n return [\n {\n path: 'http_error',\n message: responseObj.message as string[],\n },\n ];\n }\n\n if (typeof responseObj.message === 'string') {\n return [{ path: 'http_error', message: [responseObj.message] }];\n }\n\n if (responseObj.error && typeof responseObj.error === 'string') {\n return [{ path: 'http_error', message: [responseObj.error] }];\n }\n }\n\n return [{ path: 'http_error', message: ['An error occurred'] }];\n }\n\n getMessage(exception: HttpException): string {\n const response = exception.getResponse();\n\n if (typeof response === 'string') {\n return response;\n }\n\n if (typeof response === 'object' && response !== null) {\n const responseObj = response as Record<string, unknown>;\n\n if (typeof responseObj.message === 'string') {\n return responseObj.message;\n }\n\n if (responseObj.error && typeof responseObj.error === 'string') {\n return responseObj.error;\n }\n }\n\n return 'An error occurred';\n }\n}\n"],"mappings":";;;;;;;;;;;;;AAGO,IAAM,2BAAN,MAA+B;AAAA,EACpC,uBAAuB,WAA0C;AAC/D,UAAM,WAAW,UAAU,YAAY;AAEvC,QAAI,OAAO,aAAa,YAAY,aAAa,MAAM;AACrD,YAAM,cAAc;AAEpB,UAAI,MAAM,QAAQ,YAAY,OAAO,GA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EAChE;AAAA,EAEA,WAAW,WAAkC;AAC3C,UAAM,WAAW,UAAU,YAAY;AAEvC,QAAI,OAAO,aAAa,UAAU;AAChC,aAAO;AAAA,IACT;AAEA,QAAI,OAAO,aAAa,YAAY,aAAa,MAAM;AACrD,YAAM,cAAc;AAEpB,UAAI,OAAO,YAAY,YAAY,UAAU;AAC3C,eAAO,YAAY;AAAA,MACrB;AAEA,UAAI,YAAY,SAAS,OAAO,YAAY,UAAU,UAAU;AAC9D,eAAO,YAAY;AAAA,MACrB;AAAA,IACF;AAEA,WAAO;AAAA,EACT;AACF;","names":["Injectable","Injectable","HttpException","Injectable","Injectable","HttpException"]}
1
+ {"version":3,"sources":["../src/formatters/validation-error.formatter.ts","../src/formatters/prisma-exception.formatter.ts","../src/formatters/dto-validation.formatter.ts","../src/filter/global-exception.filter.ts","../src/services/exception-handler.service.ts","../src/formatters/http-exception.formatter.ts","../src/formatters/dto-exception.formatter.ts","../src/constants/default-messages.ts","../src/formatters/unknown-exception.formatter.ts","../src/module/exception-handler.module.ts","../src/utils/http-error.formatter.ts"],"sourcesContent":["import { HttpException, ValidationError } from '@nestjs/common';\nimport { ErrorMessage } from '../interfaces/error-message.interface';\n\nexport class ValidationErrorFormatter {\n formatValidationErrors(exception: HttpException): ErrorMessage[] {\n const response = exception.getResponse();\n\n if (typeof response === 'object' && response !== null) {\n const responseObj = response as Record<string, unknown>;\n\n if (Array.isArray(responseObj.message)) {\n const messages = responseObj.message;\n\n if (messages.length > 0 && typeof messages[0] === 'object' && 'property' in messages[0]) {\n return this.formatNestedValidationErrors(messages as ValidationError[]);\n }\n\n return [\n {\n path: 'http_error',\n message: messages as string[],\n },\n ];\n }\n }\n\n return [\n {\n path: 'http_error',\n message: ['Validation failed'],\n },\n ];\n }\n\n private formatNestedValidationErrors(errors: ValidationError[]): ErrorMessage[] {\n return errors.map((error) => ({\n path: error.property,\n message: error.constraints ? Object.values(error.constraints) : ['Validation error'],\n }));\n }\n}\n","import { Injectable } from '@nestjs/common';\nimport { ErrorMessage } from '../interfaces/error-message.interface';\nimport { ExceptionFormatter } from '../interfaces/exception-formatter.interface';\n\ninterface PrismaError {\n code?: string;\n meta?: Record<string, unknown>;\n message?: string;\n clientVersion?: string;\n}\n\n@Injectable()\nexport class PrismaExceptionFormatter implements ExceptionFormatter {\n supports(exception: unknown): boolean {\n if (!exception || typeof exception !== 'object') {\n return false;\n }\n\n const error = exception as Record<string, unknown>;\n const hasErrorCode = typeof error.code === 'string';\n const hasClientVersion = typeof error.clientVersion === 'string';\n const hasMeta = typeof error.meta === 'object';\n\n return hasErrorCode || (hasClientVersion && hasMeta);\n }\n\n format(exception: unknown): ErrorMessage[] {\n return this.formatError(exception as PrismaError);\n }\n\n message(_exception: unknown): string {\n return 'Database error';\n }\n\n formatError(exception: PrismaError): ErrorMessage[] {\n const code = exception.code;\n\n if (code) {\n return this.formatPrismaError(exception);\n }\n\n const message = exception.message || '';\n if (message.includes('validation') || message.includes('Rust') || message.includes('panic')) {\n return this.formatQueryError(exception);\n }\n\n if (message.includes('initialization') || message.includes('connect')) {\n return this.formatInitializationError(exception);\n }\n\n return this.formatUnknownError(exception);\n }\n\n private formatPrismaError(exception: PrismaError): ErrorMessage[] {\n const code = exception.code;\n const meta = exception.meta;\n\n switch (code) {\n case 'P2002': {\n const target = meta?.target as string[] | undefined;\n const field = target?.[0] || 'field';\n return [\n {\n path: field,\n message: [`A record with this ${field} already exists.`],\n },\n ];\n }\n case 'P2003': {\n const fieldName = meta?.field_name as string | undefined;\n return [\n {\n path: fieldName || 'field',\n message: [`The referenced ${fieldName || 'record'} does not exist.`],\n },\n ];\n }\n case 'P2005': {\n const fieldName = meta?.field_name as string | undefined;\n return [\n {\n path: fieldName || 'field',\n message: [`The value for ${fieldName || 'field'} is invalid.`],\n },\n ];\n }\n case 'P2006': {\n const fieldName = meta?.field_name as string | undefined;\n return [\n {\n path: fieldName || 'field',\n message: [`The ${fieldName || 'field'} field is required.`],\n },\n ];\n }\n case 'P2025': {\n return [\n {\n path: 'record',\n message: ['The requested record does not exist.'],\n },\n ];\n }\n default:\n return [\n {\n path: 'database',\n message: ['Database operation failed.'],\n },\n ];\n }\n }\n\n private formatQueryError(exception: PrismaError): ErrorMessage[] {\n const message = exception.message || '';\n let errorMessage = 'Invalid database query.';\n\n if (message.includes('panic')) {\n errorMessage = 'Database engine panic occurred.';\n }\n\n return [\n {\n path: 'database',\n message: [errorMessage],\n },\n ];\n }\n\n private formatInitializationError(exception: PrismaError): ErrorMessage[] {\n return [\n {\n path: 'database',\n message: [`Database initialization error: ${exception.message || 'Unknown error'}`],\n },\n ];\n }\n\n private formatUnknownError(exception: unknown): ErrorMessage[] {\n return [\n {\n path: 'unknown',\n message:\n exception instanceof Error\n ? [exception.message]\n : ['An unexpected database error occurred.'],\n },\n ];\n }\n}\n","import { Injectable } from '@nestjs/common';\nimport { HttpException } from '@nestjs/common';\nimport { ErrorMessage } from '../interfaces/error-message.interface';\n\ninterface ValidationError {\n property: string;\n constraints?: Record<string, string>;\n children?: ValidationError[];\n}\n\n@Injectable()\nexport class DtoValidationFormatter {\n formatDtoValidationException(exception: HttpException): ErrorMessage[] {\n const responseBody: unknown = exception.getResponse();\n\n if (\n typeof responseBody === 'object' &&\n responseBody !== null &&\n 'message' in responseBody &&\n Array.isArray((responseBody as Record<string, unknown>).message)\n ) {\n const messages = (responseBody as Record<string, unknown>).message as unknown[];\n const firstMessage = messages[0];\n\n if (\n firstMessage &&\n typeof firstMessage === 'object' &&\n firstMessage !== null &&\n 'property' in firstMessage\n ) {\n const validationErrors = messages as ValidationError[];\n return validationErrors.map((error: ValidationError) => ({\n path: error.property,\n message: error.constraints ? Object.values(error.constraints) : ['Validation error'],\n }));\n }\n\n if (typeof firstMessage === 'string') {\n return [\n {\n path: 'http_error',\n message: messages as string[],\n },\n ];\n }\n }\n\n return [\n {\n path: 'http_error',\n message:\n typeof responseBody === 'object' && responseBody !== null && 'message' in responseBody\n ? [(responseBody as Record<string, unknown>).message as string]\n : ['An HTTP error occurred'],\n },\n ];\n }\n}\n","import {\n ExceptionFilter,\n Catch,\n ArgumentsHost,\n HttpException,\n HttpStatus,\n Logger,\n NotFoundException,\n} from '@nestjs/common';\nimport { Request, Response } from 'express';\nimport { ExceptionHandlerService } from '../services/exception-handler.service';\nimport { ErrorResponse, ErrorMessage } from '../interfaces/error-message.interface';\nimport { ExceptionHandlerConfig } from '../interfaces/exception-handler-config.interface';\n\n@Catch()\nexport class GlobalExceptionFilter implements ExceptionFilter {\n private readonly logger = new Logger(GlobalExceptionFilter.name);\n private config: ExceptionHandlerConfig;\n\n constructor(\n private exceptionHandlerService?: ExceptionHandlerService,\n config?: ExceptionHandlerConfig,\n ) {\n this.config = config || { enableLogging: true, hideStackTrace: false };\n }\n\n private getService(): ExceptionHandlerService {\n if (!this.exceptionHandlerService) {\n this.exceptionHandlerService = new ExceptionHandlerService();\n }\n return this.exceptionHandlerService;\n }\n\n catch(exception: unknown, host: ArgumentsHost): void {\n const ctx = host.switchToHttp();\n const response = ctx.getResponse<Response>();\n const request = ctx.getRequest<Request>();\n\n const { errors, message } = this.getService().formatException(exception);\n let status = this.getStatusCode(exception);\n\n let finalErrors = errors;\n let finalMessage = message;\n\n if (exception instanceof NotFoundException) {\n const exceptionResponse = exception.getResponse();\n if (\n typeof exceptionResponse === 'object' &&\n exceptionResponse !== null &&\n 'message' in exceptionResponse\n ) {\n const msg = exceptionResponse.message;\n if (typeof msg === 'string' && msg.includes('Cannot')) {\n status = HttpStatus.NOT_FOUND;\n finalMessage = 'Route Not Found';\n finalErrors = [\n {\n path: 'route',\n message: [msg],\n },\n ];\n }\n }\n }\n\n const errorResponse: ErrorResponse = {\n success: false,\n message: finalMessage,\n errorMessages: finalErrors,\n };\n\n if (this.config.enableLogging) {\n this.logError(request, status, finalErrors, exception);\n }\n\n response.status(status).json(errorResponse);\n }\n\n private getStatusCode(exception: unknown): number {\n if (exception instanceof HttpException) {\n return exception.getStatus();\n }\n return HttpStatus.INTERNAL_SERVER_ERROR;\n }\n\n private logError(\n request: Request,\n status: number,\n errorMessages: ErrorMessage[],\n exception: unknown,\n ): void {\n const method = request.method;\n const url = request.url;\n const timestamp = new Date().toISOString();\n\n const logData = {\n timestamp,\n method,\n url,\n status,\n errorMessages,\n stack: this.config.hideStackTrace ? undefined : (exception as Error)?.stack,\n };\n\n this.logger.error(`${method} ${url} - ${status}`, JSON.stringify(logData));\n }\n}\n","import { Injectable } from '@nestjs/common';\nimport { ExceptionFormatter } from '../interfaces/exception-formatter.interface';\nimport { ErrorMessage } from '../interfaces/error-message.interface';\nimport { PrismaExceptionFormatter } from '../formatters/prisma-exception.formatter';\nimport { HttpExceptionFormatter } from '../formatters/http-exception.formatter';\nimport { DtoExceptionFormatter } from '../formatters/dto-exception.formatter';\nimport { UnknownExceptionFormatter } from '../formatters/unknown-exception.formatter';\n\n@Injectable()\nexport class ExceptionHandlerService {\n private formatters: ExceptionFormatter[] = [];\n private defaultFormatter: ExceptionFormatter;\n\n constructor() {\n this.defaultFormatter = new UnknownExceptionFormatter();\n this.registerFormatters();\n }\n\n private registerFormatters(): void {\n this.formatters = [\n new PrismaExceptionFormatter(),\n new HttpExceptionFormatter(),\n new DtoExceptionFormatter(),\n ];\n }\n\n registerFormatter(formatter: ExceptionFormatter): void {\n this.formatters.push(formatter);\n }\n\n getFormatter(exception: unknown): ExceptionFormatter {\n for (const formatter of this.formatters) {\n if (formatter.supports(exception)) {\n return formatter;\n }\n }\n return this.defaultFormatter;\n }\n\n formatException(exception: unknown): { errors: ErrorMessage[]; message: string } {\n const formatter = this.getFormatter(exception);\n const errors = formatter.format(exception);\n const message = formatter.message(exception);\n\n return { errors, message };\n }\n\n formatErrors(exception: unknown): ErrorMessage[] {\n const formatter = this.getFormatter(exception);\n return formatter.format(exception);\n }\n\n getErrorMessage(exception: unknown): string {\n const formatter = this.getFormatter(exception);\n return formatter.message(exception);\n }\n\n getAllFormatters(): ExceptionFormatter[] {\n return [...this.formatters];\n }\n}\n","import { HttpException } from '@nestjs/common';\nimport { ExceptionFormatter } from '../interfaces/exception-formatter.interface';\nimport { ErrorMessage } from '../interfaces/error-message.interface';\n\nexport class HttpExceptionFormatter implements ExceptionFormatter {\n supports(exception: unknown): boolean {\n return exception instanceof HttpException;\n }\n\n format(exception: unknown): ErrorMessage[] {\n const httpException = exception as HttpException;\n const response = httpException.getResponse();\n\n if (typeof response === 'string') {\n return [{ path: 'http_error', message: [response] }];\n }\n\n if (typeof response === 'object' && response !== null) {\n const responseObj = response as Record<string, unknown>;\n\n if (responseObj.message && Array.isArray(responseObj.message)) {\n return [\n {\n path: 'http_error',\n message: responseObj.message as string[],\n },\n ];\n }\n\n if (responseObj.message && typeof responseObj.message === 'string') {\n return [{ path: 'http_error', message: [responseObj.message as string] }];\n }\n\n if (responseObj.error && typeof responseObj.error === 'string') {\n return [{ path: 'http_error', message: [responseObj.error] }];\n }\n }\n\n return [{ path: 'http_error', message: ['An error occurred'] }];\n }\n\n message(exception: unknown): string {\n const httpException = exception as HttpException;\n const response = httpException.getResponse();\n\n if (typeof response === 'string') {\n return response;\n }\n\n if (typeof response === 'object' && response !== null) {\n const responseObj = response as Record<string, unknown>;\n\n if (responseObj.message && typeof responseObj.message === 'string') {\n return responseObj.message as string;\n }\n\n if (responseObj.error && typeof responseObj.error === 'string') {\n return responseObj.error as string;\n }\n }\n\n return 'An error occurred';\n }\n}\n","import { ValidationError } from '@nestjs/common';\nimport { ExceptionFormatter } from '../interfaces/exception-formatter.interface';\nimport { ErrorMessage } from '../interfaces/error-message.interface';\n\nexport class DtoExceptionFormatter implements ExceptionFormatter {\n supports(exception: unknown): boolean {\n if (!exception || typeof exception !== 'object') {\n return false;\n }\n\n const error = exception as Record<string, unknown>;\n return (\n Array.isArray(error.validationErrors) ||\n (Array.isArray(error.children) && error.constraints !== undefined)\n );\n }\n\n format(exception: unknown): ErrorMessage[] {\n const error = exception as Record<string, unknown>;\n const validationErrors = error.validationErrors as ValidationError[] | undefined;\n const children = error.children as ValidationError[] | undefined;\n\n if (validationErrors) {\n return this.formatValidationErrors(validationErrors);\n }\n\n if (children) {\n return this.formatChildrenErrors(children);\n }\n\n return [{ path: 'unknown', message: ['Validation failed'] }];\n }\n\n message(exception: unknown): string {\n const error = exception as Record<string, unknown>;\n const validationErrors = error.validationErrors as ValidationError[] | undefined;\n const children = error.children as ValidationError[] | undefined;\n\n if (validationErrors && validationErrors.length > 0) {\n const firstError = validationErrors[0];\n const constraints = firstError.constraints;\n if (constraints) {\n return Object.values(constraints)[0];\n }\n }\n\n if (children && children.length > 0) {\n return 'Validation failed for nested fields';\n }\n\n return 'Validation failed';\n }\n\n private formatValidationErrors(errors: ValidationError[]): ErrorMessage[] {\n return errors.flatMap((error) => {\n const constraints = error.constraints;\n if (constraints) {\n return [\n {\n path: error.property,\n message: Object.values(constraints),\n },\n ];\n }\n return [];\n });\n }\n\n private formatChildrenErrors(children: ValidationError[]): ErrorMessage[] {\n return children.flatMap((child) => {\n const constraints = child.constraints;\n if (constraints) {\n return [\n {\n path: child.property,\n message: Object.values(constraints),\n },\n ];\n }\n return [];\n });\n }\n}\n","export const DEFAULT_ERROR_MESSAGES = {\n UNKNOWN_ERROR: 'An unexpected error occurred',\n VALIDATION_ERROR: 'Validation failed',\n DATABASE_ERROR: 'Database error',\n NOT_FOUND: 'Resource not found',\n UNAUTHORIZED: 'Unauthorized access',\n FORBIDDEN: 'Access forbidden',\n CONFLICT: 'Conflict occurred',\n BAD_REQUEST: 'Bad request',\n};\n\nexport const PRISMA_ERROR_MESSAGES: Record<string, string> = {\n P2002: 'A record with this {field} already exists.',\n P2003: 'This {field} does not exist.',\n P2005: 'Invalid value for {field}.',\n P2006: 'Invalid format for {field}.',\n P2025: 'Record not found.',\n};\n\nexport const DEFAULT_PATH = 'unknown';\n","import { ExceptionFormatter } from '../interfaces/exception-formatter.interface';\nimport { ErrorMessage } from '../interfaces/error-message.interface';\nimport { DEFAULT_PATH } from '../constants/default-messages';\n\nexport class UnknownExceptionFormatter implements ExceptionFormatter {\n supports(_exception: unknown): boolean {\n return true;\n }\n\n format(_exception: unknown): ErrorMessage[] {\n return [\n {\n path: DEFAULT_PATH,\n message: ['Something went wrong'],\n },\n ];\n }\n\n message(_exception: unknown): string {\n return 'Internal Server Error';\n }\n}\n","import { DynamicModule, Module } from '@nestjs/common';\nimport { ExceptionHandlerService } from '../services/exception-handler.service';\nimport { GlobalExceptionFilter } from '../filter/global-exception.filter';\nimport { ExceptionHandlerConfig } from '../interfaces/exception-handler-config.interface';\nimport { PrismaExceptionFormatter } from '../formatters/prisma-exception.formatter';\nimport { DtoExceptionFormatter } from '../formatters/dto-exception.formatter';\nimport { HttpExceptionFormatter } from '../formatters/http-exception.formatter';\nimport { UnknownExceptionFormatter } from '../formatters/unknown-exception.formatter';\n\n@Module({})\nexport class ExceptionHandlerModule {\n static forRoot(config?: ExceptionHandlerConfig): DynamicModule {\n const providers = [\n ExceptionHandlerService,\n {\n provide: GlobalExceptionFilter,\n useFactory: (service: ExceptionHandlerService) => {\n return new GlobalExceptionFilter(service, config);\n },\n inject: [ExceptionHandlerService],\n },\n ];\n\n return {\n module: ExceptionHandlerModule,\n providers,\n exports: [ExceptionHandlerService, GlobalExceptionFilter],\n global: true,\n };\n }\n\n static forFeature(config?: ExceptionHandlerConfig): DynamicModule {\n return this.forRoot(config);\n }\n}\n\n// Initialize formatters\nexport function initializeFormatters(service: ExceptionHandlerService): void {\n service.registerFormatter(new PrismaExceptionFormatter());\n service.registerFormatter(new DtoExceptionFormatter());\n service.registerFormatter(new HttpExceptionFormatter());\n service.registerFormatter(new UnknownExceptionFormatter());\n}\n","import { HttpException } from '@nestjs/common';\nimport { ErrorMessage } from '../interfaces/error-message.interface';\n\nexport class HttpErrorFormatter {\n formatHttpException(exception: HttpException): ErrorMessage[] {\n const response = exception.getResponse();\n\n if (typeof response === 'string') {\n return [{ path: 'http_error', message: [response] }];\n }\n\n if (typeof response === 'object' && response !== null) {\n const responseObj = response as Record<string, unknown>;\n\n if (Array.isArray(responseObj.message)) {\n return [\n {\n path: 'http_error',\n message: responseObj.message as string[],\n },\n ];\n }\n\n if (typeof responseObj.message === 'string') {\n return [{ path: 'http_error', message: [responseObj.message] }];\n }\n\n if (responseObj.error && typeof responseObj.error === 'string') {\n return [{ path: 'http_error', message: [responseObj.error] }];\n }\n }\n\n return [{ path: 'http_error', message: ['An error occurred'] }];\n }\n\n getMessage(exception: HttpException): string {\n const response = exception.getResponse();\n\n if (typeof response === 'string') {\n return response;\n }\n\n if (typeof response === 'object' && response !== null) {\n const responseObj = response as Record<string, unknown>;\n\n if (typeof responseObj.message === 'string') {\n return responseObj.message;\n }\n\n if (responseObj.error && typeof responseObj.error === 'string') {\n return responseObj.error;\n }\n }\n\n return 'An error occurred';\n }\n}\n"],"mappings":";;;;;;;;;;;;;AAGO,IAAM,2BAAN,MAA+B;AAAA,EACpC,uBAAuB,WAA0C;AAC/D,UAAM,WAAW,UAAU,YAAY;AAEvC,QAAI,OAAO,aAAa,YAAY,aAAa,MAAM;AACrD,YAAM,cAAc;AAEpB,UAAI,MAAM,QAAQ,YAAY,OAAO,GAAG;AACtC,cAAM,WAAW,YAAY;AAE7B,YAAI,SAAS,SAAS,KAAK,OAAO,SAAS,CAAC,MAAM,YAAY,cAAc,SAAS,CAAC,GAAG;AACvF,iBAAO,KAAK,6BAA6B,QAA6B;AAAA,QACxE;AAEA,eAAO;AAAA,UACL;AAAA,YACE,MAAM;AAAA,YACN,SAAS;AAAA,UACX;AAAA,QACF;AAAA,MACF;AAAA,IACF;AAEA,WAAO;AAAA,MACL;AAAA,QACE,MAAM;AAAA,QACN,SAAS,CAAC,mBAAmB;AAAA,MAC/B;AAAA,IACF;AAAA,EACF;AAAA,EAEQ,6BAA6B,QAA2C;AAC9E,WAAO,OAAO,IAAI,CAAC,WAAW;AAAA,MAC5B,MAAM,MAAM;AAAA,MACZ,SAAS,MAAM,cAAc,OAAO,OAAO,MAAM,WAAW,IAAI,CAAC,kBAAkB;AAAA,IACrF,EAAE;AA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AO,YAAY,UAAU,UAAU;AAC9D,eAAO,YAAY;AAAA,MACrB;AAAA,IACF;AAEA,WAAO;AAAA,EACT;AACF;","names":["Injectable","Injectable","HttpException","Injectable","Injectable","HttpException"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nestjs-exception-handler",
3
- "version": "4.5.1",
3
+ "version": "4.6.0",
4
4
  "description": "A production-grade global exception handling system for NestJS applications",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",
@@ -42,7 +42,7 @@
42
42
  "peerDependencies": {
43
43
  "@nestjs/common": "^10.0.0 || ^11.0.0",
44
44
  "@nestjs/core": "^10.0.0 || ^11.0.0",
45
- "@prisma/client": "^5.0.0 || ^7.0.0",
45
+ "@prisma/client": ">=5.0.0 <8.0.0",
46
46
  "reflect-metadata": "^0.1.13 || ^0.2.0",
47
47
  "rxjs": "^7.8.0"
48
48
  },
@@ -50,7 +50,7 @@
50
50
  "@nestjs/common": "^11.0.0",
51
51
  "@nestjs/core": "^11.0.0",
52
52
  "@nestjs/testing": "^11.0.0",
53
- "@prisma/client": "^5.0.0 || ^7.0.0",
53
+ "@prisma/client": ">=5.0.0 <8.0.0",
54
54
  "@types/express": "^4.17.17",
55
55
  "@types/jest": "^29.5.0",
56
56
  "@types/node": "^20.0.0",