public static ApiError fromThrowable(Throwable t) {
        // Avoid populating the error message if it's a generic one. Also don't populate error
        // message for UNKNOWN_SERVER_ERROR to ensure we don't leak sensitive information.
        Throwable throwableToBeEncoded = Errors.maybeUnwrapException(t);
        Errors error = Errors.forException(throwableToBeEncoded);
        String message = error == Errors.UNKNOWN_SERVER_ERROR ||
            error.message().equals(throwableToBeEncoded.getMessage()) ? null : throwableToBeEncoded.getMessage();
        return new ApiError(error, message);
    }
Encapsulates an error code (via the Errors enum) and an optional message. Generally, the optional message is only
defined if it adds information over the default message associated with the error code.

This is an internal class (like every class in the requests package).
clients/src/main/java/org/apache/kafka/common/requests/ApiError.java