Skip to main content

createErrorFactory()

createErrorFactory<Code>(errorType): (code, details?) => CodedError

Creates a factory function for generating CodedError instances of a specific type. The factory is tree-shakable: if not imported, it won't be bundled.


Type Parametersโ€‹

Code: Code extends numberโ€‹

The numeric error codes allowed for this factory.


Parametersโ€‹

errorType: stringโ€‹

The error type/category (e.g., "Animation", "Semaphore").


Returnsโ€‹

A factory function that creates CodedError instances.


Sinceโ€‹

2.0.0


Exampleโ€‹

const createAnimationError = createErrorFactory<100 | 101 | 102>("Animation");
throw createAnimationError(101, { id: "missing" });