private CompletionStage<Response<ByteString>> haltActiveBackfillInstances(Backfill backfill, Client client) { return CompletableFutures.allAsList( retrieveBackfillStatuses(backfill).stream() .filter(BackfillResource::isActiveState) .map(RunStateData::workflowInstance) .map(workflowInstance -> haltActiveBackfillInstance(workflowInstance, client)) .collect(toList())) .handle((result, throwable) -> { if (throwable != null || result.contains(Boolean.FALSE)) { return Response.forStatus( Status.INTERNAL_SERVER_ERROR .withReasonPhrase( "some active instances cannot be halted, however no new ones will be triggered")); } else { return Response.ok(); } }); }