Skip to content

Commit

Permalink
Update http config with more gracefully request
Browse files Browse the repository at this point in the history
  • Loading branch information
ChrisKruegerDev committed Dec 4, 2024
1 parent f388d53 commit 19758ca
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 6 deletions.
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

0 comments on commit 19758ca

Please sign in to comment.