An alternative to retry() is retryWhen(). This takes a lambda expression that is passed the exception along with the number of times we have retried the Flow so far. If the lambda expression returns true, we retry the Flow again. If the lambda expression returns false, the exception continues along to the FlowCollector.

The lambda expression might look at the exception and choose different rules based upon details of the exception (e.g., exception type).

You can learn more about this in:
Run Edit