Skip to content

Commit 19758ca

Browse files
Update http config with more gracefully request
1 parent f388d53 commit 19758ca

File tree

3 files changed

+12
-6
lines changed

3 files changed

+12
-6
lines changed

tmdb-api/src/commonMain/kotlin/app/moviebase/tmdb/TmdbClientConfig.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@ class TmdbClientConfig {
1212
internal var tmdbAuthCredentials: TmdbAuthCredentials? = null
1313

1414
var expectSuccess: Boolean = true
15-
var useCache: Boolean = false
16-
var useTimeout: Boolean = false
17-
var maxRetriesOnException: Int? = null
15+
var useCache: Boolean = true
16+
var useTimeout: Boolean = true
17+
var maxRequestRetries: Int? = 5
1818

1919
internal var httpClientConfigBlock: (HttpClientConfig<*>.() -> Unit)? = null
2020
internal var httpClientBuilder: (() -> HttpClient)? = null

tmdb-api/src/commonMain/kotlin/app/moviebase/tmdb/core/HttpClientFactory.kt

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,10 +82,16 @@ internal object HttpClientFactory {
8282
}
8383

8484
// see https://ktor.io/docs/client-retry.html
85-
config.maxRetriesOnException?.let {
85+
config.maxRequestRetries?.let {
8686
install(HttpRequestRetry) {
8787
exponentialDelay()
88-
retryOnServerErrors(maxRetries = it)
88+
retryIf(it) { _, httpResponse ->
89+
when {
90+
httpResponse.status.value in 500..599 -> true
91+
httpResponse.status == HttpStatusCode.TooManyRequests -> true
92+
else -> false
93+
}
94+
}
8995

9096
retryOnExceptionIf(maxRetries = it) { _, cause ->
9197
when {

tmdb-api/src/jvmTest/kotlin/app/moviebase/tmdb/TmdbTestEnvironment.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ fun defaultTmdbConfiguration(
4444

4545
useCache = true
4646
useTimeout = true
47-
maxRetriesOnException = 3
47+
maxRequestRetries = 3
4848

4949
httpClient(OkHttp) {
5050
logging {

0 commit comments

Comments
 (0)