@luolapeikko/ts-common
    Preparing search index...

    Function errorWith

    • Wraps an error in a custom error type using a callback function.

      Type Parameters

      • ET extends Error

        The custom error type that extends Error.

      Parameters

      • err: unknown

        The original error or error message to wrap.

      • callback: (message?: string) => ET

        A function that takes an optional message and returns an instance of the custom error type.

      Returns ET

      An instance of the custom error type with the original message and stack trace.

      try {
      // ...
      } catch (err) {
      const customError = errorWith(err, (msg) => new CustomError(msg));
      throw customError;
      }

      v0.3.0