@jossmac/lil-libs
    Preparing search index...

    Function parseError

    • Extracts a human-readable error message from unknown thrown input.

      Native Error instances and error-like objects with a string message use that message. String inputs are returned as-is. Everything else receives the fallback message.

      • value: unknown

        Thrown value or error payload: native Error, error-like object, string, or anything else.

      • fallbackMessage: string = UNKNOWN_ERROR_MESSAGE

        Message returned when value has no extractable message. Defaults to UNKNOWN_ERROR_MESSAGE.

      value.message for errors and error-like objects; strings as-is; otherwise fallbackMessage.

      parseError(new Error("Boom")); // "Boom"
      parseError("Something went wrong"); // "Something went wrong"
      parseError({ message: "from object" }); // "from object"
      parseError(null); // "An unknown error occurred."
      parseError({ message: 123 }); // "An unknown error occurred."
      parseError(null, "Custom fallback"); // "Custom fallback"