Vizel API / core/src / wrapAsVizelError
Function: wrapAsVizelError()
ts
function wrapAsVizelError(error, contextOrOptions?): VizelError;Defined in: packages/core/src/utils/errorHandling.ts:182
Wrap an unknown error as a VizelError.
If the error is already a VizelError, returns it unchanged (the code and context options are not applied). Otherwise, creates a new VizelError with the specified code (or UNKNOWN_ERROR).
Parameters
| Parameter | Type | Description |
|---|---|---|
error | unknown | The error to wrap |
contextOrOptions? | | string | WrapAsVizelErrorOptions | Optional context string or options object |
Returns
A VizelError instance (the original if already a VizelError)
Example
typescript
// With context string
const vizelError = wrapAsVizelError(e, "During initialization");
// With options object
const vizelError = wrapAsVizelError(e, {
context: "During initialization",
code: "INVALID_CONFIG",
});