@xylabs/error

Base functionality used throughout XY Labs TypeScript/JavaScript libraries
Install
Using npm:
npm install {{name}}
Using yarn:
yarn add {{name}}
Using pnpm:
pnpm add {{name}}
Using bun:
bun add {{name}}
License
See the LICENSE file for license rights and limitations (LGPL-3.0-only).
Reference
packages
error
### .temp-typedoc
### functions
### <a id="assertError"></a>assertError
@xylabs/error
function assertError(
value,
assert,
defaultMessage): undefined;
Throws an Error based on the assert configuration when a value fails validation.
Parameters
value
unknown
The value being validated
assert
AssertConfig | undefined
Assertion config controlling the error message
defaultMessage
string
Fallback message if no custom message is provided
Returns
undefined
### <a id="handleError"></a>handleError
@xylabs/error
function handleError<T>(error, handler): T;
Invokes the handler if the value is an Error, otherwise re-throws it.
Type Parameters
T
T
Parameters
error
any
The caught value to inspect
handler
(error) => T
Callback invoked with the Error if it is one
Returns
T
The handler's return value
### <a id="handleErrorAsync"></a>handleErrorAsync
@xylabs/error
function handleErrorAsync<T>(error, handler): Promise<T>;
Async version of handleError. Invokes the async handler if the value is an Error, otherwise re-throws it.
Type Parameters
T
T
Parameters
error
any
The caught value to inspect
handler
(error) => Promise<T>
Async callback invoked with the Error if it is one
Returns
Promise<T>
The handler's resolved return value
### type-aliases
### <a id="AssertConfig"></a>AssertConfig
@xylabs/error
type AssertConfig = string | AssertCallback | boolean;
Configuration for assertion behavior: a static message string, a boolean toggle, or a callback.