npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@protobuf-ts-toolkit/grpc-error

v1.0.0

Published

Typed error classes and interceptor for gRPC applications

Readme

@protobuf-ts-toolkit/grpc-error

Error classes and interceptor for gRPC applications, with support for Google RPC error details.

Installation

npm install @protobuf-ts-toolkit/grpc-error

Client Usage (Interceptor)

import { GrpcWebFetchTransport } from '@protobuf-ts/grpcweb-transport';
import { createErrorInterceptor, ValidationError, NotFoundError } from '@protobuf-ts-toolkit/grpc-error';

const transport = new GrpcWebFetchTransport({
  baseUrl: 'https://api.example.com',
  interceptors: [createErrorInterceptor()],
});

const client = new MyServiceClient(transport);

try {
  await client.createUser({ name: '' });
} catch (e) {
  if (e instanceof ValidationError) {
    // Access parsed field violations from error details
    for (const detail of e.details) {
      if (detail.type === 'badRequest') {
        for (const v of detail.fieldViolations) {
          console.log(`${v.field}: ${v.description}`);
        }
      }
    }
  }

  if (e instanceof NotFoundError) {
    console.log(`Resource not found: ${e.localizedMessage}`);
  }
}

Interceptor Features

  • Captures call-site stack traces for better debugging (gRPC connection pooling normally obscures this)
  • Parses rich error details from grpc-status-details-bin trailer
  • Maps gRPC status codes to typed error classes
  • Optional onError callback for global error handling
createErrorInterceptor({
  onError: (error) => {
    if (error instanceof UnauthenticatedError) {
      router.push('/login');
    }
  },
});

Server Usage (Encoding)

import { ValidationError, encodeGrpcStatus } from '@protobuf-ts-toolkit/grpc-error';

// Throw typed errors on server
const error = new ValidationError({
  localizedMessage: 'Invalid email format',
  details: [{
    type: 'badRequest',
    fieldViolations: [{ field: 'email', description: 'Must be a valid email' }]
  }]
});

// Encode to binary for grpc-status-details-bin trailer
const binary = encodeGrpcStatus(error);

Error Classes

  • GrpcError - Base class for all gRPC errors
  • ValidationError - Invalid input (INVALID_ARGUMENT)
  • NotFoundError - Resource not found (NOT_FOUND)
  • AlreadyExistsError - Resource already exists (ALREADY_EXISTS)
  • PermissionDeniedError - Permission denied (PERMISSION_DENIED)
  • UnauthenticatedError - Not authenticated (UNAUTHENTICATED)
  • UnavailableError - Service unavailable (UNAVAILABLE)
  • DeadlineExceededError - Request timeout (DEADLINE_EXCEEDED)
  • AbortedError - Operation aborted (ABORTED)
  • RaceUpdateError - Concurrent modification conflict (ABORTED)
  • UnknownError - Unknown error (UNKNOWN)

Error Details

Supports all standard Google RPC error detail types:

  • BadRequestDetail - Field violations
  • ErrorInfoDetail - Structured error info with reason and metadata
  • RetryInfoDetail - Retry delay information
  • DebugInfoDetail - Debug information (stack traces, detail)
  • QuotaFailureDetail - Quota violation details
  • PreconditionFailureDetail - Precondition failures
  • ResourceInfoDetail - Resource information
  • RequestInfoDetail - Request identification
  • HelpDetail - Help links
  • LocalizedMessageDetail - Localized error messages