3.0.0 • Published 11 months ago

@jallohtech/nestjs-exception-handler v3.0.0

Weekly downloads
-
License
ISC
Repository
github
Last release
11 months ago

��# NestJS Global Exception Handler A robust, configurable global exception filter for NestJS applications that standardizes error responses across microservices. ## Features - =؀� Comprehensive error handling for NestJS applications - =� � Automatic error classification and categorization - =��� Configurable logging options - =���� Sensitive data sanitization - =��� External logging support - =�� Production-mode error masking ## Installation Install the package and its required dependency using npm: bash npm install @jallohtech/nestjs-exception-handler @nestjs/axios ## Usage ### Basic Setup Important: The HttpModule must be imported before GlobalExceptionFilterModule typescript import { Module } from '@nestjs/common'; import { GlobalExceptionFilterModule } from '@jallohtech/nestjs-exception-handler'; import { HttpModule } from '@nestjs/axios'; @Module({ imports: [ HttpModule, // This must come BEFORE GlobalExceptionFilterModule GlobalExceptionFilterModule.register({ serviceName: 'your-service-name', loggingServiceUrl: 'https://your-logging-service.com/logs' }) ] }) export class AppModule {} ### Configuration Options typescript interface GlobalExceptionFilterConfig { loggingServiceUrl?: string; serviceName?: string; options?: { verbose?: boolean; logToExternal?: boolean; productionMode?: boolean; externalLoggingRateLimit?: { maxRequests: number; timeWindowMs: number; }; externalLoggingTimeoutMs?: number; }; } ## Error Categories - VALIDATION_ERROR - AUTHENTICATION_ERROR - AUTHORIZATION_ERROR - NOT_FOUND - CONFLICT - EXTERNAL_SERVICE_ERROR - INTERNAL_ERROR - RATE_LIMIT_ERROR - SERVICE_UNAVAILABLE - UNKNOWN_ERROR ## Advanced Configuration typescript import { Module } from '@nestjs/common'; import { GlobalExceptionFilterModule } from '@jallohtech/nestjs-exception-handler'; import { HttpModule } from '@nestjs/axios'; @Module({ imports: [ HttpModule, GlobalExceptionFilterModule.register({ serviceName: 'user-service', loggingServiceUrl: 'https://logging.example.com/logs', options: { verbose: true, logToExternal: true, productionMode: process.env.NODE_ENV === 'production', externalLoggingRateLimit: { maxRequests: 10, timeWindowMs: 60000 // 1 minute } } }) ] }) export class AppModule {} ## Response Format When an exception is caught, the filter returns a standardized JSON response: json { "statusCode": 400, "category": "validation_error", "timestamp": "2025-03-04T12:34:56.789Z", "path": "/api/users", "message": "Invalid user data", "requestId": "abc123", "serviceName": "user-service", "componentName": "UserController", "resolved": null } ## Dependencies - NestJS Common (^6.0.0 - ^11.0.0) - NestJS Core (^6.0.0 - ^11.0.0) - @nestjs/axios (Required) ## Common Issues - Missing HttpService error: Make sure you've imported HttpModule before GlobalExceptionFilterModule - Configuration issues: Ensure the serviceName is provided in the register method ## License ISC License ## Contributing Contributions are welcome! Please feel free to submit a Pull Request. ## Author Ibrahim Bakarr Jalloh - JallohTech(https://github.com/jallohtech)

3.0.0

11 months ago

1.1.5

11 months ago

1.1.3

11 months ago

1.1.2

11 months ago