Hi an a method annotated with @Retryable annotation
@Override
@Retryable( value = FeignException.class, maxAttempts = 2, backoff = @Backoff(delay = 100))
public Map<String, String> fetchMediaResponseFromMediaIds(Set<String> mediaIds) {
try { code....
} catch (TBadRequestException badRequestException){
log.error("Bad Headers for Media Client Call with exception {} ",new SCXDealerSettingBadRequestException(InformationalErrorCode.DSS_ACC_BADREQUEST, HttpStatus.BAD_REQUEST, ErrorConstants.REQUEST_HEADERS_MISSING),badRequestException);
}
catch (FeignException feignException){
final TFeignErrorUtils.ErrorDetails errorDetails = getErrorDetailsOrNull(feignException.content());
log.error("Error getting Media Urls from Media Client {} with details {}" ,feignException );
}
catch (Exception exception){
log.error("Error getting Media Urls from Media Client {} with exception" , GenericErrorCode.DSS_MEDIA_GENERIC,exception);
}
}
return null;
}
Retry Policy class
public class FeignExceptionServerErrorRetryPolicy implements RetryPolicy {
@Override
public boolean canRetry(RetryContext context) {
Throwable lastThrowable = context.getLastThrowable();
if (lastThrowable instanceof FeignException) {
FeignException feignException = (FeignException) lastThrowable;
int httpStatusCode = feignException.status();
return String.valueOf(httpStatusCode).startsWith("5");
}
return false;
}
@Override
public RetryContext open(RetryContext parent) {
return null;
}
@Override
public void close(RetryContext context) {
}
@Override
public void registerThrowable(RetryContext context, Throwable throwable) {
}
}
I want this retry method to run only when feignException is a server error ie 5xx error code . How can i do that without using if and else. I have retry policy defined but not sure how to inject it in the methods retry .