{"id":48680,"library":"nestjs-grpc-exceptions","title":"NestJS gRPC Exceptions","description":"A lightweight library (v0.2.2) for NestJS that provides gRPC exception wrappers corresponding to standard gRPC status codes (e.g., NotFound, InvalidArgument). It includes a server-side exception filter (GrpcServerExceptionFilter) to automatically convert thrown exceptions to gRPC errors, and client-side interceptors (GrpcToHttpInterceptor, HttpToGrpcInterceptor) to bridge between HTTP and gRPC error formats. Requires @grpc/grpc-js, @nestjs/common, @nestjs/core, and @nestjs/microservices as peer dependencies. Compatible with NestJS 9 and 10. Actively maintained with TypeScript types included.","status":"active","version":"0.2.2","language":"javascript","source_language":"en","source_url":"https://github.com/mohsenbostan/nestjs-grpc-exceptions","tags":["javascript","typescript"],"install":[{"cmd":"npm install nestjs-grpc-exceptions","lang":"bash","label":"npm"},{"cmd":"yarn add nestjs-grpc-exceptions","lang":"bash","label":"yarn"},{"cmd":"pnpm add nestjs-grpc-exceptions","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Required for gRPC error codes and gRPC client/server implementation.","package":"@grpc/grpc-js","optional":false},{"reason":"Required for NestJS decorators, filters, and interceptors.","package":"@nestjs/common","optional":false},{"reason":"Required for NestJS application framework and dependency injection.","package":"@nestjs/core","optional":false},{"reason":"Required for NestJS microservices support including gRPC transport.","package":"@nestjs/microservices","optional":false}],"imports":[{"note":"ESM import is recommended; CommonJS require() may cause issues with certain bundlers or NestJS versions.","wrong":"const { GrpcServerExceptionFilter } = require('nestjs-grpc-exceptions')","symbol":"GrpcServerExceptionFilter","correct":"import { GrpcServerExceptionFilter } from 'nestjs-grpc-exceptions'"},{"note":"Named export only; default import is not available.","wrong":"import GrpcNotFoundException from 'nestjs-grpc-exceptions'","symbol":"GrpcNotFoundException","correct":"import { GrpcNotFoundException } from 'nestjs-grpc-exceptions'"},{"note":"Used as an @Injectable() interceptor in NestJS controllers.","wrong":"","symbol":"GrpcToHttpInterceptor","correct":"import { GrpcToHttpInterceptor } from 'nestjs-grpc-exceptions'"}],"quickstart":{"code":"import { Module } from '@nestjs/common';\nimport { APP_FILTER } from '@nestjs/core';\nimport { GrpcServerExceptionFilter, GrpcNotFoundException, GrpcInvalidArgumentException } from 'nestjs-grpc-exceptions';\n\n@Module({\n  providers: [\n    {\n      provide: APP_FILTER,\n      useClass: GrpcServerExceptionFilter,\n    },\n  ],\n})\nexport class GrpcModule {}\n\n// In a service:\nthrow new GrpcNotFoundException('User not found.');\nthrow new GrpcInvalidArgumentException('Invalid input.');","lang":"typescript","description":"Shows how to import and use the global exception filter and throw gRPC exceptions in a NestJS module."},"warnings":[{"fix":"Use APP_FILTER provider as shown in the documentation.","message":"GrpcServerExceptionFilter must be registered as a global filter (APP_FILTER) to catch all exceptions; if registered locally, it may not intercept unhandled exceptions.","severity":"gotcha","affected_versions":"<0.2.0"},{"fix":"Import all symbols directly from 'nestjs-grpc-exceptions'.","message":"Upgrading from v0.1.x to v0.2.0 changed export paths: previously exceptions were available under 'nestjs-grpc-exceptions/exceptions'.","severity":"breaking","affected_versions":">=0.2.0"},{"fix":"Ensure your application uses @nestjs/microservices gRPC transport.","message":"The library only supports NestJS gRPC microservices; it does not work with standalone gRPC servers or other frameworks.","severity":"gotcha","affected_versions":">=0.0.0"},{"fix":"Apply the interceptor to controller methods that call gRPC services.","message":"GrpcToHttpInterceptor converts gRPC errors to HTTP exceptions and requires the client to handle HTTP exceptions appropriately; if not set up, errors may be lost.","severity":"gotcha","affected_versions":">=0.0.0"}],"env_vars":null,"search_vec":"'10':70 '9':68 'activ':71 'automat':34 'bridg':49 'client':43 'client-sid':42 'code':20 'compat':65 'convert':35 'correspond':15 'depend':64 'e.g':21 'error':40,54 'except':3,13,30,37 'filter':31 'format':55 'grpc':2,12,18,39,53 'grpc/grpc-js':57 'grpcserverexceptionfilt':32 'grpctohttpinterceptor':46 'http':51 'httptogrpcinterceptor':47 'includ':25,76 'interceptor':45 'invalidargu':23 'javascript':77 'librari':6 'lightweight':5 'maintain':72 'nestj':1,9,67 'nestjs/common':58 'nestjs/core':59 'nestjs/microservices':61 'notfound':22 'peer':63 'provid':11 'requir':56 'server':28 'server-sid':27 'side':29,44 'standard':17 'status':19 'thrown':36 'type':75 'typescript':74,78 'v0.2.2':7 'wrapper':14","created_at":"2026-06-07T16:57:53.211630+00:00","updated_at":"2026-06-07T16:57:53.211630+00:00","problems":[{"fix":"Run 'npm install nestjs-grpc-exceptions' and ensure tsconfig.json includes 'node_modules/@types'.","cause":"Package not installed or TypeScript compiler cannot resolve types.","error":"Cannot find module 'nestjs-grpc-exceptions' or its corresponding type declarations."},{"fix":"Use ES6 import syntax: import { GrpcNotFoundException } from 'nestjs-grpc-exceptions'","cause":"Using CommonJS require incorrectly with a named export.","error":"GrpcNotFoundException is not a constructor"},{"fix":"Add it to a module's providers array, preferably as an APP_FILTER.","cause":"The filter is not registered as a provider in any module.","error":"No provider for 'GrpcServerExceptionFilter' (appears in error stack)"}],"ecosystem":"npm","meta_description":null,"install_score":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":null,"cli_name":null,"cli_version":null,"type":"library","homepage":"https://github.com/mohsenbostan/nestjs-grpc-exceptions","github":"https://github.com/mohsenbostan/nestjs-grpc-exceptions","docs":null,"changelog":null,"pypi":null,"npm":"nestjs-grpc-exceptions","openapi_spec":null,"status_page":null,"smithery":null,"categories":["testing"],"base_url":null,"auth_type":null,"provenance":{"verified_status":null,"verified_at":null,"last_verified":"2026-06-07","next_check":"2026-09-05","install_tag":null}}