Try throwException
Opened this issue · 0 comments
jainh commented
How to throw exception if one of the operations faile
Try<CompletableFuture<Boolean>, IOException> request = Try.withCatch(() -> Convertor.fromJsonToPojo(payload, PepRequest.class))
.onFail(e -> LOG.error("failed to serialize Json payload:{} exception:{}",payload, e))
.map(pepReq -> (new PdpRequest()).copyFromParameters(pepReq, user.getUsername()))
.onFail(e -> LOG.error("failed to create pdp request model because of the following reason:{}",e))
.flatMap(pdpRequest -> Try.withCatch(() -> new ObjectMapper().writeValueAsString(pdpRequest)))
.onFail(e -> LOG.error("failed to convert pdp request to json reason:{}",e.getMessage()))
.flatMap(requestBody -> Try.withCatch(() -> httpClient.execute(requestBody)))
.onFail(e -> LOG.error("failed to execute request:{} because of the following reason:{}",payload, e.getMessage()));
If successful return completablefuture