Skip to main content

Function: createErrorKit()

Each call declares its own class (never shared), so two kits' instances never satisfy each other's instanceof; name becomes both the runtime .name and the stack-trace identity.

createErrorKit<R extends Registry, Name extends string>(name: Name, registry: R): ErrorKit<R>

Defined in: kit.ts:140

Each call declares its own class (never shared), so two kits' instances never satisfy each other's instanceof; name becomes both the runtime .name and the stack-trace identity.

Type Parameters

R

R extends Registry

Name

Name extends string

Parameters

name

Name

registry

R

Returns

ErrorKit<R>

Example

const REGISTRY = {
  WIDGET_NOT_FOUND: detail<{ widgetId: string }>(404),
  STORAGE_FAILED: fault<{ cause?: string }>(500),
} as const satisfies Record<string, number>

const kit = createErrorKit('AppError', REGISTRY)
export const AppError = kit.ErrorClass

kit.throwError('WIDGET_NOT_FOUND', { widgetId: 'w1' })
// -> AppError { code: 'WIDGET_NOT_FOUND', status: 404, meta: { widgetId: 'w1' } }