Repository: apache/kafka
File: raft/src/main/java/org/apache/kafka/raft/RaftUtil.java (Java)

Code before:
                        .setListeners(voter.listeners().toDescribeQuorumResponseListeners())
                );
            }
            response.setNodes(nodes);
        }
        return response;
    }

    public static AddRaftVoterRequestData addVoterRequest(
        String clusterId,
        int timeoutMs,
        ReplicaKey voter,
        Endpoints listeners
    ) {
        return new AddRaftVoterRequestData()
            .setClusterId(clusterId)
            .setTimeoutMs(timeoutMs)
            .setVoterId(voter.id())
            .setVoterDirectoryId(voter.directoryId().orElse(ReplicaKey.NO_DIRECTORY_ID))
            .setListeners(listeners.toAddVoterRequest());
    }

    public static AddRaftVoterResponseData addVoterResponse(
        Errors error,
        String errorMessage
    ) {
        if (errorMessage == null) {
            errorMessage = !Errors.NONE.equals(error) ? error.message() : null;
        } else if (Errors.NONE.equals(error)) {
            errorMessage = null;
        }
        return new AddRaftVoterResponseData()
            .setErrorCode(error.code())
            .setErrorMessage(errorMessage);
    }

    public static RemoveRaftVoterRequestData removeVoterRequest(
        String clusterId,
        ReplicaKey voter
    ) {
        return new RemoveRaftVoterRequestData()
            .setClusterId(clusterId)
            .setVoterId(voter.id())
            .setVoterDirectoryId(voter.directoryId().orElse(ReplicaKey.NO_DIRECTORY_ID));
    }

    public static RemoveRaftVoterResponseData removeVoterResponse(
        Errors error,
        String errorMessage
    ) {
        if (errorMessage == null) {

Review comment (suggestion):
it might be more concise to just do
```
if (errorMessage == null && error != Errors.NONE) {
    errorMessage = error.message();
}
```
what do you think about adding a comment as well?
```
// return the provided errorMessage if it exists, Errors.NONE should have a null message
```



Code after:
    }

    public static AddRaftVoterRequestData addVoterRequest(
        String clusterId,
        int timeoutMs,
        ReplicaKey voter,
        Endpoints listeners,
        boolean ackWhenCommitted
    ) {
        return new AddRaftVoterRequestData()
            .setClusterId(clusterId)
            .setTimeoutMs(timeoutMs)
            .setVoterId(voter.id())
            .setVoterDirectoryId(voter.directoryId().orElse(ReplicaKey.NO_DIRECTORY_ID))
            .setListeners(listeners.toAddVoterRequest())
            .setAckWhenCommitted(ackWhenCommitted);
    }

    public static AddRaftVoterResponseData addVoterResponse(
        Errors error,
        String errorMessage
    ) {
        // return the provided errorMessage if it exists, Errors.NONE should have a null message
        if (errorMessage == null && error != Errors.NONE) {
            errorMessage = error.message();
        }
        return new AddRaftVoterResponseData()
            .setErrorCode(error.code())
            .setErrorMessage(errorMessage);
    }

    public static RemoveRaftVoterRequestData removeVoterRequest(
        String clusterId,
        ReplicaKey voter
    ) {
        return new RemoveRaftVoterRequestData()
            .setClusterId(clusterId)
            .setVoterId(voter.id())
            .setVoterDirectoryId(voter.directoryId().orElse(ReplicaKey.NO_DIRECTORY_ID));
    }

    public static RemoveRaftVoterResponseData removeVoterResponse(
        Errors error,
        String errorMessage
    ) {
        // return the provided errorMessage if it exists, Errors.NONE should have a null message
        if (errorMessage == null && error != Errors.NONE) {
            errorMessage = error.message();
        }
        return new RemoveRaftVoterResponseData()
            .setErrorCode(error.code())