spring-retry
spring-retry copied to clipboard
Add "exposeOriginalException" option on @Retryable
Because of issue #82, I add an option on @Retryable
.
It decides that if original exception ( the cause wrapped in ExhaustedRetryException
) will be thrown if ExhaustedRetryException
is triggered.
Please review, thanks !
@getupdown Please sign the Contributor License Agreement!
Click here to manually synchronize the status of this Pull Request.
See the FAQ for frequently asked questions.
@getupdown Thank you for signing the Contributor License Agreement!
Thanks for that, and for the tests. I was wondering if it might be better implemented a layer below the interceptors, so that someone using RetryTemplate
directly could benefit. The @Retryable
annotation might have to pick up an attribute still, or we could think about a new annotation, but let's leave that discussion for now. Do you think maybe we could add an attribute to the RetryContext
that the RetryTemplate
would recognize and unwrap the exception before throwing?
@dsyer Thanks for your replying !
I've thought about your approach carefully. I found that, if exposeOriginalException
is added into RetryContext
, it means , RetryPolicy
must be modified . According to the method doExecute
, context
is generated from retryPolicy
and state
. I don't think it's reasonable that the relative information should be maintained inRetryPolicy
.
So, how about setting a boolean value directly named exposeOriginalException
as a field of RetryTemplate
?
I think, the option is only for the specific implementation of RetryOperation
, namely RetryTemplate
.
Sorry for the delay. It's a tough decision. RetryTemplate
tends to be global, but the decision to rethrow the original exception might be local. So on balance I guess you are right in the first place and we should simply support this feature in the annotation, at least to start with. Maybe I'll ask @garyrussell for an opinion before merging.
From #82 @dsyer said
It's not really a @CircuitBreaker feature is it (the RetryTemplate always wraps the last failed exception)?
Actually, the RetryTemplate
has a boolean throwLastExceptionOnExhausted
(false by default).
So, maybe we should add a (default
?) setter on RetryOperations
and set throwLastExceptionOnExhausted
to true if the annotation has this property set; then you wouldn't need to unwrap the ExhaustedRetryException
(because it wouldn't be wrapped in the first place).
Superseded by the https://github.com/spring-projects/spring-retry/commit/d3698b8cf490a6c81e8a2996c451ac7961ecb53e.
Thank you for contribution any way; looking forward for more!