Skip to content

Commit f93d6ea

Browse files
committed
honor retry-after header in anilist client
1 parent d70a8f1 commit f93d6ea

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

src/main/kotlin/org/snd/module/MetadataModule.kt

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,11 +220,22 @@ class MetadataModule(
220220
return AniListClient(
221221
okHttpClient = okHttpClient,
222222
name = "AniList",
223+
223224
rateLimiterConfig = RateLimiterConfig.custom()
224225
.limitRefreshPeriod(Duration.ofSeconds(5))
225226
.limitForPeriod(5)
226227
.timeoutDuration(Duration.ofSeconds(5))
227-
.build()
228+
.build(),
229+
230+
retryConfig = RetryConfig.custom<Any>()
231+
.intervalBiFunction { _, result ->
232+
if (result.isRight) return@intervalBiFunction 5000
233+
234+
val exception = result.left
235+
return@intervalBiFunction if (exception is HttpException && exception.code == 429) {
236+
exception.headers["retry-after"]?.toLong()?.times(1000) ?: 5000
237+
} else 5000
238+
}.build()
228239
)
229240
}
230241

0 commit comments

Comments
 (0)