Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,10 @@
import org.springframework.retry.RetryContext;
import org.springframework.retry.RetryListener;
import org.springframework.retry.support.RetryTemplate;
import org.springframework.retry.support.RetryTemplateBuilder;
import org.springframework.util.CollectionUtils;
import org.springframework.util.StreamUtils;
import org.springframework.web.client.ResourceAccessException;
import org.springframework.web.client.ResponseErrorHandler;

/**
Expand All @@ -47,6 +49,7 @@
*
* @author Christian Tzolov
* @author SriVarshan P
* @author Seunggyu Lee
*/
@AutoConfiguration
@ConditionalOnClass(RetryUtils.class)
Expand All @@ -58,9 +61,10 @@ public class SpringAiRetryAutoConfiguration {
@Bean
@ConditionalOnMissingBean
public RetryTemplate retryTemplate(SpringAiRetryProperties properties) {
return RetryTemplate.builder()
RetryTemplateBuilder builder = RetryTemplate.builder()
.maxAttempts(properties.getMaxAttempts())
.retryOn(TransientAiException.class)
.retryOn(ResourceAccessException.class)
.exponentialBackoff(properties.getBackoff().getInitialInterval(), properties.getBackoff().getMultiplier(),
properties.getBackoff().getMaxInterval())
.withListener(new RetryListener() {
Expand All @@ -71,8 +75,21 @@ public <T, E extends Throwable> void onError(RetryContext context, RetryCallback
logger.warn("Retry error. Retry count: {}, Exception: {}", context.getRetryCount(),
throwable.getMessage(), throwable);
}
})
.build();
});

// Optionally add WebFlux pre-response network errors if present
try {
Class<?> webClientRequestEx = Class
.forName("org.springframework.web.reactive.function.client.WebClientRequestException");
@SuppressWarnings("unchecked")
Class<? extends Throwable> exClass = (Class<? extends Throwable>) webClientRequestEx;
builder.retryOn(exClass);
}
catch (ClassNotFoundException ignore) {
// WebFlux not on classpath; skip
}

return builder.build();
}

@Bean
Expand Down