Skip to content
This repository has been archived by the owner on Jun 21, 2023. It is now read-only.

Get last exception #83

Open
jflefebvre06 opened this issue Aug 5, 2020 · 5 comments
Open

Get last exception #83

jflefebvre06 opened this issue Aug 5, 2020 · 5 comments

Comments

@jflefebvre06
Copy link

Could you please add a way to get the last exception from a BackoffStrategy.

@elennick
Copy link
Owner

elennick commented Nov 27, 2020

@jflefebvre06 - You can already check the last exception that generated a retry by looking in the Status object - look in the documentation here and let me know if this already covers what you are asking for: https://github.com/elennick/retry4j#call-status

@jflefebvre06
Copy link
Author

No, Status is not accessible from BackoffStrategy

public interface BackoffStrategy {

    Duration getDurationToWait(int numberOfTriesFailed, Duration delayBetweenAttempts);

    default void validateConfig(RetryConfig config) {}

}

@elennick
Copy link
Owner

Could you share an example of what you're trying to get access to? Do you have your own custom BackoffStrategy implementation that contains logic that can throw an exception?

@jflefebvre06
Copy link
Author

The use case is to manage http too many requests

Duration getDurationToWait(int numberOfTriesFailed, Duration delayBetweenAttempts) {

   if(exception.getHttpStatus()==429)
       return Duration.ofMinutes(1);
   else
       return Duration.ofSeconds(2);
}

@elennick
Copy link
Owner

@jflefebvre06 ok I understand... you want to be able to have more granular retry control over a single callable. Retry4j does not support this type of case at the moment. I'm not sure that implementing it inside a backoff strategy would be the correct approach... a better design would probably be to allow multiple retry configurations for a single callable, so that different configs could handle different exception types or return values. Please feel free to take a shot at an implementation and open a PR if you would like. Let me know if you want to discuss the design further before you do so. Thanks!

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

No branches or pull requests

2 participants