Registry / development / grpc-web-error-details

grpc-web-error-details

JSON →
library1.1.0jsnpmunverified

Deserializes `grpc-status-details-bin` metadata from gRPC-Web errors into Google's richer error model (Status + typed error details like BadRequest, RetryInfo). Version 1.1.0, stable with sporadic updates. Requires `grpc-web` (>=1.2.1) and `google-protobuf` (>=3.15.8). Uses `instanceof` type guards for TypeScript. Unlike `@stackpath/node-grpc-error-details` for Node, this is specifically for browser gRPC-Web clients.

npm install grpc-web-error-details
INSTALL
IMPORT
SIG · GRPC-WEB-ERROR-DET
G
grpc-web-error-details
developmentjavascriptv1.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.

statusFromError
import { statusFromError } from 'grpc-web-error-details'
import errorDetails from 'grpc-web-error-details'
Default import does not exist; use named import.
BadRequest
import { BadRequest } from 'grpc-web-error-details'
import { BadRequest } from 'google-protobuf'
BadRequest is re-exported from this package for convenience.
Status
import { Status } from 'grpc-web-error-details'
import { Status } from 'grpc-web'
Status here is the deserialized google.rpc.Status message.

Shows how to catch a gRPC-Web error, deserialize status details, and iterate over BadRequest field violations using instanceof type guards.

import { statusFromError, BadRequest } from 'grpc-web-error-details'; try { await client.someRpc(); } catch (err) { const [status, details] = statusFromError(err); if (status && details) { for (const detail of details) { if (detail instanceof BadRequest) { for (const violation of detail.getFieldViolationsList()) { console.log(`Field: ${violation.getField()}, Desc: ${violation.getDescription()}`); } } } } }
Debug
Known issues
gotchaThe function returns [null, null] if the error cannot be deserialized; always check before using.
fix
Use if (status && details) before accessing members.
affects: *
gotchaError details are protobuf message instances; use getter methods (e.g., .getField()) not property access.
fix
Use detail.getFieldViolationsList() instead of detail.fieldViolations.
affects: *
deprecatedgoogle-protobuf v3.x is in maintenance mode; consider migrating to @bufbuild/protobuf.
fix
Switch to @bufbuild/protobuf and adapt library usage accordingly (note: grpc-web-error-details currently depends on google-protobuf).
affects: >=1.0.0
gotchaTypeScript `instanceof` checks only work if you import the specific detail class (e.g., `BadRequest`) from this package.
fix
Always import detail classes from 'grpc-web-error-details', not from 'google-protobuf'.
affects: *
gotchaThis library only works in the browser with grpc-web; for Node.js use @stackpath/node-grpc-error-details.
fix
Use @stackpath/node-grpc-error-details on Node.js.
affects: *
Errors
Common errors & fixes
TypeError: Cannot read properties of undefined (reading 'getFieldViolationsList')
Accessing methods on a null/undefined detail after statusFromError returned [null, null].
fix
Always check if status and details are truthy before iterating.
Object prototype may only be an Object or null: undefined
Using `require('grpc-web-error-details')` in ESM environment.
fix
Use `import { statusFromError } from 'grpc-web-error-details'`.
Property 'statusFromError' does not exist on type 'typeof import("...")'
Importing default instead of named export.
fix
Use `import { statusFromError } from 'grpc-web-error-details'`.
Upgrade
Version history
1.1.0latest on npm
Audit
Dependencies
google-protobufrequiredProvides protobuf message classes (e.g., BadRequest) used by the deserialization library
grpc-webrequiredRequired for gRPC-Web clients that produce the errors parsed by this library
Agent activity
45 hits · last 30 days
node
38
Resources
grpc-web-error-details — npm install grpc-web-error-details · libregistry