Rethrow undeclared exceptions #263
-
Not sure if this is a "works as designed" problem, but it seems to be useful to support this use-case. I need the retry mechanism to be triggered only for declared exceptions and let others be rethrown. With this code: @Retryable(include = {ToRetryException.class}, recover = "recoverRetrieveFromExternal")
public String retrieveFromExternal(String arg) {
return externalService.retrieve(arg);
}
@Recover
private String recoverRetrieveFromExternal(Throwable t, String arg) {
return "Recover: " + arg;
} When an exception different from With Basically, I need this test suite to pass: @Test
void ok() {
when(externalService.retrieve(anyString())).thenReturn("TEST");
assertThat(client.retrieveFromExternal("")).isEqualTo("TEST");
}
@Test
void rethrows_the_exception() {
when(externalService.retrieve(anyString())).thenThrow(new RuntimeException());
assertThrows(RuntimeException.class, () -> client.retrieveFromExternal(""));
}
@Test
void retries_and_recovers() {
when(externalService.retrieve(anyString())).thenThrow(new ToRetryException());
assertThat(client.retrieveFromExternal("test")).isEqualTo("Recover: test");
} Is there a way to do that? Thanks! |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 11 replies
-
Don't use GitHub issues to ask questions; they are for bug reports or asking for new features; ask questions on Stack Overflow or use the Discussions tab. Change the recover method so that it only handles |
Beta Was this translation helpful? Give feedback.
-
Converting to a discussion. |
Beta Was this translation helpful? Give feedback.
Don't use GitHub issues to ask questions; they are for bug reports or asking for new features; ask questions on Stack Overflow or use the Discussions tab.
Change the recover method so that it only handles
ToRetryException
, not allThrowable
s.