tguard-js
    Preparing search index...

    Function ensureError

    • Ensures that the provided value is an Error instance.

      Parameters

      • x: unknown

        The value to ensure is an Error.

      Returns Error

      A normalized Error instance.

      This function is a convenience wrapper around normalizeError. It converts any thrown value into a proper Error object.

      try {
      throw { message: 'Something went wrong' };
      } catch (err) {
      const error = ensureError(err);
      console.log(error.message); // 'Something went wrong'
      console.log(error.cause); // { message: 'Something went wrong' }
      }

      1.0