@Override
    public StopReplicaResponse getErrorResponse(int throttleTimeMs, Throwable e) {
        Errors error = Errors.forException(e);

        StopReplicaResponseData data = new StopReplicaResponseData();
        data.setErrorCode(error.code());

        List<StopReplicaPartitionError> partitions = new ArrayList<>();
        for (StopReplicaTopicState topic : topicStates()) {
            for (StopReplicaPartitionState partition : topic.partitionStates()) {
                partitions.add(new StopReplicaPartitionError()
                    .setTopicName(topic.topicName())
                    .setPartitionIndex(partition.partitionIndex())
                    .setErrorCode(error.code()));
            }
        }
        data.setPartitionErrors(partitions);

        return new StopReplicaResponse(data);
    }
@Test
    public void testGetErrorResponse() {
        List<StopReplicaTopicState> topicStates = topicStates(true);

        Set<StopReplicaPartitionError> expectedPartitions = new HashSet<>();
        for (StopReplicaTopicState topicState : topicStates) {
            for (StopReplicaPartitionState partitionState: topicState.partitionStates()) {
                expectedPartitions.add(new StopReplicaPartitionError()
                    .setTopicName(topicState.topicName())
                    .setPartitionIndex(partitionState.partitionIndex())
                    .setErrorCode(Errors.CLUSTER_AUTHORIZATION_FAILED.code()));
            }
        }

        for (short version : STOP_REPLICA.allVersions()) {
            StopReplicaRequest.Builder builder = new StopReplicaRequest.Builder(version,
                    0, 0, 0L, false, topicStates);
            StopReplicaRequest request = builder.build();
            StopReplicaResponse response = request.getErrorResponse(0,
                    new ClusterAuthorizationException("Not authorized"));
            assertEquals(Errors.CLUSTER_AUTHORIZATION_FAILED, response.error());
            assertEquals(expectedPartitions, new HashSet<>(response.partitionErrors()));
        }
    }