r2d2
r2d2

Reputation: 19

Lost in Java Concurrency

(A follow-up question to this one)

I am struggling with Java CompletableStage and trying to understand how to properly chain error handling logic. Could someone help me wrap my head around it?

public CompletableFuture<DoStuffResponse> doStuff(
      DoStuffRequest request) {

    return stuffClient
        .doClientStuff(request)
        .thenApply(
            response -> {
              blah
              timer.stop();
              return response;
            })
        .exceptionally(
            e -> {
              if (e.getCause() instanceof ValidationException)) {
                     *stuffClient.doCustomClientStuff(request);*  // how and where to do this??
                     throw new CustomException("Validation failed doing stuff " + e.getMessage(), e);
              } else            
                  throw new OtherCustomException("Failed doing stuff " + e.getMessage(), e);
              }   
        .toCompletableFuture();
  }

...

public interface StufClient {
     CompletionStage<DoStuffResponse> doClientStuff(DoStuffRequest request);
     CompletionStage<DoStuffResponse> doCustomClientStuff(DoStuffRequest request);

Upvotes: -1

Views: 116

Answers (0)

Related Questions