Registry / testing / nice-grpc-error-details

nice-grpc-error-details

JSON →
library0.2.14jsnpmunverified

nice-grpc-error-details (v0.2.14) provides a TypeScript implementation of Google's gRPC rich error model (google.rpc.Status with details) for use with nice-grpc. It converts between gRPC service errors and typed ErrorInfo, RetryInfo, DebugInfo, QuotaFailure, BadRequest, PreconditionFailure, RequestInfo, ResourceInfo, Help, LocalizedMessage details. Updated infrequently as needed for nice-grpc compatibility. Key differentiator: integrates seamlessly with nice-grpc's error handling, supports both client and server side, and ships complete TypeScript definitions.

npm install nice-grpc-error-details
INSTALL
IMPORT
SIG · NICE-GRPC-ERROR-DE
N
nice-grpc-error-details
testingjavascriptv0.2.14
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.

toStatus
import { toStatus } from 'nice-grpc-error-details'
import toStatus from 'nice-grpc-error-details'
Default export does not exist; always use named import.
fromStatus
import { fromStatus } from 'nice-grpc-error-details'
const { fromStatus } = require('nice-grpc-error-details')
Package is ESM-first; CommonJS require may fail in Node.js without esm interoperability.
RetryInfo
import { RetryInfo } from 'nice-grpc-error-details/lib/RetryInfo'
import { RetryInfo } from 'nice-grpc-error-details'
Detail types are re-exported from root, but direct path is explicit for tree-shaking.

Creates a gRPC server that throws an error with RetryInfo detail using nice-grpc-error-details.

import { createServer, ServerError } from 'nice-grpc'; import { fromStatus } from 'nice-grpc-error-details'; import { RetryInfo } from 'nice-grpc-error-details/lib/RetryInfo'; import { Duration } from 'google-protobuf/google/protobuf/duration_pb'; const server = createServer(); server.addService(/* your service */, { async myMethod(request, ctx) { try { // ... business logic } catch (error) { // Attach error details const retryDetail = new RetryInfo().setRetryDelay( new Duration().setSeconds(5) ); const status = fromStatus({ code: 10, // ABORTED message: 'Please retry after 5 seconds', details: [retryDetail], }); throw new ServerError(status); } }, }); server.listen('0.0.0.0:8080');
Debug
Known issues
gotchaDetail types (RetryInfo, DebugInfo, etc.) are not automatically included in the root export; you must import them from their specific module paths for tree-shaking to work.
fix
Use `import { RetryInfo } from 'nice-grpc-error-details/lib/RetryInfo'` instead of root import.
affects: *
deprecatedThe package previously exported `createStatus` and `createErrorDetails`; these are deprecated in favor of `fromStatus` and `toStatus`.
fix
Replace `createStatus` with `fromStatus` and `createErrorDetails` with direct detail constructors.
affects: <0.2.0
gotchagoogle-protobuf must be installed as a direct dependency; it is not a peer dependency and may be missed if not listed explicitly.
fix
Add `google-protobuf` to your project's dependencies: `npm install google-protobuf`.
affects: *
breakingVersion 0.2.0 changed the API from using error detail constructors (e.g., `new RetryInfo()`) to importing them from subpaths. Old constructor-based imports break.
fix
Use `import { RetryInfo } from 'nice-grpc-error-details/lib/RetryInfo'` and import protobuf classes from `google-protobuf`.
affects: >=0.2.0
gotchaThe package is ESM-only; using `require()` may cause issues in environments that do not support ESM.
fix
Use ESM imports or enable esm interop in CommonJS (e.g., dynamic import()).
affects: >=0.2.0
Errors
Common errors & fixes
Cannot find module 'google-protobuf'
google-protobuf is not installed or not in node_modules.
fix
Run `npm install google-protobuf`.
RetryInfo is not a constructor
Using old import pattern (root re-export) or missing protobuf classes.
fix
Import from subpath: `import { RetryInfo } from 'nice-grpc-error-details/lib/RetryInfo'` and ensure `google-protobuf` is installed.
TypeError: fromStatus is not a function
Default import instead of named import.
fix
Use `import { fromStatus } from 'nice-grpc-error-details'`.
Upgrade
Version history
0.2.14latest on npm
Audit
Dependencies
nice-grpc-commonrequiredprovides status and metadata types used by error details
google-protobufrequiredruntime dependency for protobuf message classes
Agent activity
4 hits · last 30 days
node
4
Resources
nice-grpc-error-details — npm install nice-grpc-error-details · libregistry