Function: createException()
ts
function createException<T>(
name: string,
message: string,
code: string,
status?: number,
fatal?: boolean,
): CreatedException<T>;Factory that produces a named @nhtio/adk!BaseException subclass with a fixed printf-style message template, error code, HTTP status, and fatality flag.
Type Parameters
| Type Parameter | Default type | Description |
|---|---|---|
T extends any[] | [] | Tuple of printf format argument types. Pass a non-empty tuple to require callers to supply interpolation values at the throw site. |
Parameters
| Parameter | Type | Description |
|---|---|---|
name | string | The name property set on thrown instances (used by isNamedException). |
message | string | Printf-style template string for the error message. |
code | string | Machine-readable error code stored on the static and instance code property. |
status? | number | HTTP status code associated with this exception class. |
fatal? | boolean | When true, signals that the error is unrecoverable. |
Returns
A constructor for a @nhtio/adk!BaseException subclass with the given metadata baked in.
Remarks
Prefer this over hand-writing subclasses for simple, static exception definitions.
Example
ts
export const E_NOT_FOUND = createException<[string]>(
"E_NOT_FOUND",
"Resource %s not found",
"E_NOT_FOUND",
404,
false,
);
throw new E_NOT_FOUND(["my-id"]);