Class RetryInterceptor

java.lang.Object
com.github.mizosoft.methanol.RetryInterceptor
All Implemented Interfaces:
Methanol.Interceptor

public final class RetryInterceptor extends Object implements Methanol.Interceptor
An interceptor that retries HTTP requests based on configurable conditions.

Retry conditions are evaluated in the order they are added. The first matching condition determines the next request to send. Later conditions are not evaluated.

Example:

Retry server errors with exponential backoff:
var client = Methanol.newBuilder()
    .interceptor(RetryInterceptor.newBuilder()
        .maxRetries(3)
        .backoff(BackoffStrategy.exponential(
            Duration.ofMillis(100),
            Duration.ofSeconds(10)).withJitter())
        .onStatus(500, 502, 503, 504)
        .onException(ConnectException.class)
        .build())
    .build();
See Also: