public static ControlledShutdownResponse prepareResponse(Errors error, Set<TopicPartition> tps) {
        ControlledShutdownResponseData data = new ControlledShutdownResponseData();
        data.setErrorCode(error.code());
        ControlledShutdownResponseData.RemainingPartitionCollection pSet = new ControlledShutdownResponseData.RemainingPartitionCollection();
        tps.forEach(tp ->
            pSet.add(new RemainingPartition()
                    .setTopicName(tp.topic())
                    .setPartitionIndex(tp.partition()))
        );
        data.setRemainingPartitions(pSet);
        return new ControlledShutdownResponse(data);
    }
Possible error codes:

UNKNOWN(-1) (this is because IllegalStateException may be thrown in `KafkaController.shutdownBroker`, it would be good to improve this)
BROKER_NOT_AVAILABLE(8)
STALE_CONTROLLER_EPOCH(11)
clients/src/main/java/org/apache/kafka/common/requests/ControlledShutdownResponse.java