Skip to content

In mutiny, I want to retry a Uni<> when it fails, but the only condition to generate a failure is to throw an exception? #574

Answered by cescoffier
jiayaoO3O asked this question in Q&A
Discussion options

You must be logged in to vote

What you can do is the following:

// This is the Uni representing your call to the remote service (HTTP in your case)
Uni<Response> call = callYourService();

// Verify and retry
Uni<Response> uni = call
  .onItem().transform(resp -> {
      if (resp.statusCode() != 200) { throw new RuntimeException("not ok: " + resp.statusCode()); }
     return resp; 
  })
  .onFailure().retry().atMost(5); // Your retry

The idea is to forward a failure if the response is not a 200 and recover (retry) in that case. If would retry for every failure. You can limit the retry by failing with a specific exception and use onFailure(MySpecificException.class).retry()...

Replies: 1 comment 3 replies

Comment options

You must be logged in to vote
3 replies
@jiayaoO3O
Comment options

@cescoffier
Comment options

@jiayaoO3O
Comment options

Answer selected by jiayaoO3O
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants