Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update http config with more gracefully request #157

Merged
merged 1 commit into from
Dec 4, 2024
Merged
Show file tree
Hide file tree
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 @@ -12,9 +12,9 @@ class TmdbClientConfig {
internal var tmdbAuthCredentials: TmdbAuthCredentials? = null

var expectSuccess: Boolean = true
var useCache: Boolean = false
var useTimeout: Boolean = false
var maxRetriesOnException: Int? = null
var useCache: Boolean = true
var useTimeout: Boolean = true
var maxRequestRetries: Int? = 5

internal var httpClientConfigBlock: (HttpClientConfig<*>.() -> Unit)? = null
internal var httpClientBuilder: (() -> HttpClient)? = null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,16 @@ internal object HttpClientFactory {
}

// see https://ktor.io/docs/client-retry.html
config.maxRetriesOnException?.let {
config.maxRequestRetries?.let {
install(HttpRequestRetry) {
exponentialDelay()
retryOnServerErrors(maxRetries = it)
retryIf(it) { _, httpResponse ->
when {
httpResponse.status.value in 500..599 -> true
httpResponse.status == HttpStatusCode.TooManyRequests -> true
else -> false
}
}

retryOnExceptionIf(maxRetries = it) { _, cause ->
when {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ fun defaultTmdbConfiguration(

useCache = true
useTimeout = true
maxRetriesOnException = 3
maxRequestRetries = 3

httpClient(OkHttp) {
logging {
Expand Down
Loading