Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Try throwException #257

Open
jainh opened this issue Mar 13, 2017 · 0 comments
Open

Try throwException #257

jainh opened this issue Mar 13, 2017 · 0 comments
Labels

Comments

@jainh
Copy link

jainh commented Mar 13, 2017

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants