RequestInterceptor
Interface for intercepting network responses and deciding whether a request is retried.
A NetworkClient notifies its interceptors of the result of every attempt and asks them whether to retry it; add interceptors by deriving a client with NetworkClient.newClient. The built-in ones are created with RequestInterceptors.retryWithBackoff and RequestInterceptors.retryWhenConnected. Interceptors are asked to shouldRetry in reverse order, so add RequestInterceptors.retryWhenConnected last: it is then asked first and, while the device is offline, waits for connectivity instead of letting RequestInterceptors.retryWithBackoff use up its attempts:
val client = networkClient.newClient(
listOf(
RequestInterceptors.retryWithBackoff(maxAttempts = 3),
RequestInterceptors.retryWhenConnected(connectivity)
),
maxRetryCount = 10
)onAttemptResult and shouldRetry are called on the Tealium background thread.
Functions
Called with the result of every attempt of a request.
Determines if a network request should be retried based on the provided parameters. An interceptor that only observes results returns RetryPolicy.DoNotRetry.