code: protected <T extends OperationResponse> void completeOperation(ServerStateMachine.Result result, OperationResponse.Builder<?, T> builder, Throwable error, CompletableFuture<T> future) {
      if (isOpen()) {
        if (result != null) {
          builder.withIndex(result.index);
          builder.withEventIndex(result.eventIndex);
          if (result.result instanceof Exception) {
            error = (Exception) result.result;
          }
        }
  
        if (error == null) {
          future.complete(builder.withStatus(Response.Status.OK)
            .withResult(result != null ? result.result : null)
            .build());
        } else if (error instanceof CompletionException && error.getCause() instanceof CopycatException) {
          future.complete(builder.withStatus(Response.Status.ERROR)
            .withError(((CopycatException) error.getCause()).getType())
            .build());
        } else if (error instanceof CopycatException) {
          future.complete(builder.withStatus(Response.Status.ERROR)
            .withError(((CopycatException) error).getType())
            .build());
        } else {
          LOGGER.warn("An unexpected error occurred: {}", error);
          future.complete(builder.withStatus(Response.Status.ERROR)
            .withError(CopycatError.Type.INTERNAL_ERROR)
            .build());
        }
      }
    }
docs: Completes an operation.