@gentleduck/error
Typed, registry-driven error classes for TypeScript. Branded codes, secret-safe serialization, framework-agnostic, zero dependencies.
One registry. One class. Fully typed.
Build one error class per subsystem from a registry literal. No separate type declarations to keep in sync, no secrets leaking into a response.
Registry-driven
One error class per subsystem, built from a plain object literal mapping codes to HTTP status numbers.
Fully typed
Which codes exist, what metadata each carries, and whether metadata is required — all inferred, no separate declarations.
Secret-safe by default
`toJSON()` decides what metadata is safe to serialize, so secrets never leak into logs or API responses.
Zero dependencies
Framework-agnostic and isomorphic. Works the same in Node, edge runtimes, and the browser.
Branded types
`detail()` and `fault()` brand a plain status number, so a code from one kit can never satisfy another.
Framework integrations
Drop-in error handlers for Express, Fastify, Hono, NestJS, and Next.js Route Handlers.
Install
One import, no dependencies.
# Install
bun add @gentleduck/error
# Define a kit
import { createErrorKit, fault } from '@gentleduck/error'
export const AppError = createErrorKit('AppError', {
NOT_FOUND: fault<{ id: string }>(404),
})Free & open source
gentleduck is MIT licensed and will always be free and open source. Every package ships with full source access — fork it, modify it, own it.