Je ne peux pas trouver une méthode sur CompletableStage pour ce faire, il en a moi-même:
public static <A, B> void handleEitherException(CompletionStage<A> a, CompletionStage<B> b, Consumer<Throwable> onException) {
AtomicBoolean aCompletionStageHasFailed = new AtomicBoolean();
handleEitherException(a, onException, aCompletionStageHasFailed);
handleEitherException(b, onException, aCompletionStageHasFailed);
}
private static <U> void handleEitherException(CompletionStage<U> u, Consumer<Throwable> onException, AtomicBoolean aCompletionStageHasFailed) {
u.handle((a, t) -> {
if (t != null) {
if (aCompletionStageHasFailed.compareAndSet(false, true)) {
onException.accept(t);
throw new RuntimeException(t);
}
}
return null;
});
}
`` `