Skip to content

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

ParameterTypeDescription
errorunknownThe error to wrap
contextOrOptions?| string | WrapAsVizelErrorOptionsOptional context string or options object

Returns

VizelError

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",
});

Released under the MIT License.