# nice-grpc-error-details

> gRPC rich error model implementation for nice-grpc

Latest version **0.3.1** (published 2026-11-18) · MIT license · 0 weekly downloads

## Install

```sh
npm install nice-grpc-error-details
pnpm add nice-grpc-error-details
yarn add nice-grpc-error-details
bun add nice-grpc-error-details
```

## Health

**Score 65/100 (B)** — status: active.

Positive: has types; no vulnerabilities; recently updated; high maintenance score; high quality score.

Warnings: low downloads; no esm support; pre 1.0.

## Facts

| | |
|---|---|
| Version | 0.3.1 |
| Published | 2026-11-18 |
| First published | 2022-04-18 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 4 |
| Unpacked size | 231.4 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 542 |
| Author | Daniel Lytkin |
| Maintainers | aikoven |

## Links

- npm: https://www.npmjs.com/package/nice-grpc-error-details
- Repository: https://github.com/deeplay-io/nice-grpc
- Homepage: https://github.com/deeplay-io/nice-grpc/tree/master/packages/nice-grpc-error-details#readme
- Issues: https://github.com/deeplay-io/nice-grpc/issues
- npm.io page: https://npm.io/package/nice-grpc-error-details

## Dependencies (4)

- [long](https://npm.io/package/long.md) ^5.2.3
- [protobufjs](https://npm.io/package/protobufjs.md) ^8.0.0
- [nice-grpc-common](https://npm.io/package/nice-grpc-common.md) ^2.0.4
- [@bufbuild/protobuf](https://npm.io/package/@bufbuild/protobuf.md) ^2.2.5

## Recent versions

- 0.3.1 (latest) — 2026-11-18
- 0.3.0 — 2026-10-26
- 0.2.15 — 2026-08-04
- 0.2.14 — 2026-04-24
- 0.2.13 — 2026-04-12
- 0.2.12 — 2025-11-12
- 0.2.11 — 2025-10-01
- 0.2.10 — 2025-04-26
- 0.2.9 — 2025-03-26
- 0.2.8 — 2025-02-18
- 0.2.7 — 2024-09-24
- 0.2.6 — 2024-06-06
- 0.2.5 — 2024-03-11
- 0.2.4 — 2023-10-19
- 0.2.3 — 2023-10-17
- … 14 more at https://npm.io/package/nice-grpc-error-details/versions

## README

# nice-grpc-error-details [![npm version][npm-image]][npm-url]

[Rich error model](https://grpc.io/docs/guides/error/#richer-error-model)
implementation for [nice-grpc](https://github.com/deeplay-io/nice-grpc).

> This package is **experimental** and its API should not be considered stable.

Provides extensions to
[`ServerError`](../nice-grpc-common/src/server/ServerError.ts) and
[`ClientError`](../nice-grpc-common/src/client/ClientError.ts) which carry extra
[error details](https://github.com/googleapis/googleapis/blob/master/google/rpc/error_details.proto),
as well as server and client middleware to communicate these details via
trailing metadata.

## Installation

    npm install nice-grpc-error-details

## Usage

### Server

Attach the middleware to a server:

```ts
import {errorDetailsServerMiddleware} from 'nice-grpc-error-details';

const server = createServer().use(errorDetailsServerMiddleware);
```

Throw [`RichServerError`](src/server/RichServerError.ts) from a service
implementation method:

```ts
import {ServerError, Status} from 'nice-grpc';
import {RichServerError, BadRequest} from 'nice-grpc-error-details';

const exampleServiceImpl: ServiceImplementation<
  typeof ExampleServiceDefinition
> = {
  async exampleUnaryMethod(
    request: ExampleRequest,
  ): Promise<DeepPartial<ExampleResponse>> {
    if (!request.someField)
      throw new RichServerError(
        Status.INVALID_ARGUMENT,
        "Missing required field 'some_field'",
        [
          BadRequest.fromPartial({
            fieldViolations: [
              {
                field: 'some_field',
                description: 'Field is required',
              },
            ],
          }),
        ],
      );

    // ... method logic
  },
};
```

### Client

Attach the middleware to a client factory:

```ts
import {errorDetailsClientMiddleware} from 'nice-grpc-error-details';

const clientFactory = createClientFactory().use(errorDetailsClientMiddleware);
```

If an error with details is returned from a server, the client will receive
[`RichClientError`](src/client/RichClientError.ts):

```ts
import {Status} from 'nice-grpc';
import {RichClientError, BadRequest} from 'nice-grpc-error-details';

const fieldViolations: BadRequest_FieldViolation[] = [];

try {
  await client.exampleUnaryMethod(request);
} catch (error: unknown) {
  if (
    error instanceof RichClientError &&
    error.code === Status.INVALID_ARGUMENT
  ) {
    // loop through error details to find `BadRequest`
    for (const detail of error.extra) {
      if (detail.$type === BadRequest.$type) {
        fieldViolations.push(...detail.fieldViolations);
      }
    }
  } else {
    throw error;
  }
}
```

[npm-image]: https://badge.fury.io/js/nice-grpc-error-details.svg
[npm-url]: https://badge.fury.io/js/nice-grpc-error-details

---
_Source: https://npm.io/package/nice-grpc-error-details · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
