Registry / testing / grpc-error

grpc-error

JSON →
library1.1.0jsnpmunverified

Utility Error class for creating gRPC error responses with status codes and metadata. Version 1.1.0 is stable with no recent releases. It extends the native Error class and integrates with gRPC status codes and Metadata. Differentiates from plain errors by supporting gRPC-specific properties like code and built-in metadata handling.

npm install grpc-error
INSTALL
IMPORT
SIG · GRPC-ERROR
G
grpc-error
testingjavascriptv1.1.0
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

GRPCError
✓ const GRPCError = require('grpc-error')
✗ import GRPCError from 'grpc-error'
Package is CJS-only; does not support ESM imports directly.
GRPCError
✓ const { GRPCError } = require('grpc-error')
✗ const GRPCError = require('grpc-error').GRPCError
Default export is the class; named import does not exist.
GRPCError
✓ const GRPCError = require('grpc-error')
✗ const grpcError = require('grpc-error')
Common usage expects 'GRPCError' as the variable name.

Shows creating GRPCError with status code from @grpc/grpc-js and with custom code and metadata.

const GRPCError = require('grpc-error'); const grpc = require('@grpc/grpc-js'); // Create gRPC error with status code const error = new GRPCError('Invalid argument', grpc.status.INVALID_ARGUMENT); console.log(error.message); // 'Invalid argument' console.log(error.code); // 3 // Create with custom code and metadata const error2 = new GRPCError('Boom', 2000, { status_code: 'INVALID_TOKEN' }); console.log(error2.code); // 2000 console.log(error2.metadata.getMap()); // { status_code: 'INVALID_TOKEN' }
Debug
Known issues
gotchaThe package is CommonJS only; ESM import (import GRPCError from 'grpc-error') will fail.
fix
Use require() instead of import, or use dynamic import() as fallback.
affects: >=1.0.0
gotchaIf @grpc/grpc-js is not installed, metadata property may not be fully functional or may throw.
fix
Install @grpc/grpc-js as a peer dependency: npm install @grpc/grpc-js
affects: >=1.0.0
deprecatedThe package has not been updated since 2019; consider using gRPC's built-in error utilities or a more maintained alternative.
fix
Migrate to grpc-js native errors or use a fork.
affects: >=1.0.0
Errors
Common errors & fixes
TypeError: Class constructor GRPCError cannot be invoked without 'new'
Trying to call GRPCError as a function without 'new'.
fix
Instantiate with 'new GRPCError(...)'
Module not found: Can't resolve 'grpc'
Missing peer dependency '@grpc/grpc-js' (or older 'grpc' package).
fix
Run: npm install @grpc/grpc-js
Error: grpc.Metadata is not a constructor
Using @grpc/grpc-js version that changed the export path.
fix
Ensure you require: const grpc = require('@grpc/grpc-js');
Upgrade
Version history
1.1.0latest on npm
Audit
Dependencies
@grpc/grpc-jsoptionalPeer dependency for gRPC status codes and Metadata class
Agent activity
27 hits · last 30 days
node
24
OpenAI (training)
2
Resources
grpc-error — npm install grpc-error · libregistry