@8hobbies/utils
    Preparing search index...

    Function convertErrorToString

    • Converts an error in catch clause to string.

      Parameters

      • error: unknown

        The error object.

      Returns string

      1. If error is a string, returns error.
      2. If error is an object that has a message field, returns error.message.
      3. Otherwise, apply JSON.stringify to error and returns the result.
      try {
      // ...
      } catch (e) {
      console.error(`Something failed: ${convertErrorToString(e)}`);
      }