Skip to content

Commit

Permalink
Merge pull request #1657 from puncleV/make-retry-exception-constructo…
Browse files Browse the repository at this point in the history
…r-public

(refactor) make RetryException constructor public
  • Loading branch information
fatroom authored Nov 7, 2024
2 parents d04791e + 903d150 commit 10f0109
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 1 deletion.
17 changes: 17 additions & 0 deletions riptide-failsafe/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,23 @@ RetryPolicy.<ClientHttpResponse>builder()
.build();
```

By default, you can use RetryException in your routes to retry the request:

```java
retryClient.get()
.dispatch(
series(), on(CLIENT_ERROR).call(
response -> {
if (specificCondition(response)) {
throw new RetryException(response); // we will retry this one
} else {
throw new AnyOtherException(response); // we wont retry this one
}
}
)
).join()
```

Failsafe supports dynamically computed delays using a custom function.

Riptide: Failsafe offers implementations that understand:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
@API(status = STABLE)
public final class RetryException extends HttpResponseException {

RetryException(final ClientHttpResponse response) throws IOException {
public RetryException(final ClientHttpResponse response) throws IOException {
super("Retrying response", response);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,17 @@
import org.zalando.riptide.autoconfigure.MetricsTestAutoConfiguration;
import org.zalando.riptide.autoconfigure.OpenTracingTestAutoConfiguration;
import org.zalando.riptide.autoconfigure.RiptideClientTest;
import org.zalando.riptide.failsafe.RetryException;

import java.util.concurrent.CompletionException;

import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.springframework.http.HttpStatus.Series.SERVER_ERROR;
import static org.springframework.http.HttpStatus.Series.CLIENT_ERROR;
import static org.springframework.test.web.client.ExpectedCount.times;
import static org.springframework.test.web.client.match.MockRestRequestMatchers.requestTo;
import static org.springframework.test.web.client.response.MockRestResponseCreators.withServerError;
import static org.springframework.test.web.client.response.MockRestResponseCreators.withBadRequest;
import static org.zalando.riptide.Bindings.on;
import static org.zalando.riptide.Navigators.series;
import static org.zalando.riptide.failsafe.RetryRoute.retry;
Expand Down Expand Up @@ -54,4 +57,17 @@ void shouldRetryForAtMostMaxRetriesTimes() {

server.verify();
}

@Test
void shouldRetryForCustomRetryException() {
server.expect(times(3), requestTo("http://retry-test")).andRespond(withBadRequest());


assertThrows(CompletionException.class,
() -> retryClient.get().dispatch(series(), on(CLIENT_ERROR).call(response -> {
throw new RetryException(response);
})).join());

server.verify();
}
}

0 comments on commit 10f0109

Please sign in to comment.