docs: protected <T extends OperationResponse> void completeOperation(OperationResult result, OperationResponse.Builder<?, T> builder, Throwable error, CompletableFuture<T> future) {
      if (result != null) {
        builder.withIndex(result.index());
        builder.withEventIndex(result.eventIndex());
        if (result.failed()) {
          error = result.error();
        }
      }
  
      if (error == null) {
        if (result == null) {
          future.complete(builder.withStatus(RaftResponse.Status.ERROR)
              .withError(RaftError.Type.PROTOCOL_ERROR)
              .build());
        } else {
          future.complete(builder.withStatus(RaftResponse.Status.OK)
              .withResult(result.result())
              .build());
        }
      } else if (error instanceof CompletionException && error.getCause() instanceof RaftException) {
        future.complete(builder.withStatus(RaftResponse.Status.ERROR)
            .withError(((RaftException) error.getCause()).getType(), error.getMessage())
            .build());
      } else if (error instanceof RaftException) {
        future.complete(builder.withStatus(RaftResponse.Status.ERROR)
            .withError(((RaftException) error).getType(), error.getMessage())
            .build());
      } else if (error instanceof PrimitiveException.ServiceException) {
        log.warn("An application error occurred: {}", error.getCause());
        future.complete(builder.withStatus(RaftResponse.Status.ERROR)
            .withError(RaftError.Type.APPLICATION_ERROR)
            .build());
      } else {
        log.warn("An unexpected error occurred: {}", error);
        future.complete(builder.withStatus(RaftResponse.Status.ERROR)
            .withError(RaftError.Type.PROTOCOL_ERROR, error.getMessage())
            .build());
      }
    }