Handle TooManyRequestsException during downloading
This commit is contained in:
@@ -6,4 +6,8 @@ import java.util.Date
|
||||
class TooManyRequestExceptions(
|
||||
val url: String,
|
||||
val retryAt: Date?,
|
||||
) : IOException()
|
||||
) : IOException() {
|
||||
|
||||
val retryAfter: Long
|
||||
get() = if (retryAt == null) 0 else (retryAt.time - System.currentTimeMillis()).coerceAtLeast(0)
|
||||
}
|
||||
|
||||
@@ -37,6 +37,7 @@ import okio.IOException
|
||||
import okio.buffer
|
||||
import okio.sink
|
||||
import org.koitharu.kotatsu.R
|
||||
import org.koitharu.kotatsu.core.exceptions.TooManyRequestExceptions
|
||||
import org.koitharu.kotatsu.core.network.CommonHeaders
|
||||
import org.koitharu.kotatsu.core.network.MangaHttpClient
|
||||
import org.koitharu.kotatsu.core.parser.MangaDataRepository
|
||||
@@ -277,7 +278,12 @@ class DownloadWorker @AssistedInject constructor(
|
||||
publishState(currentState.copy(isPaused = false, error = null))
|
||||
} else {
|
||||
countDown--
|
||||
delay(DOWNLOAD_ERROR_DELAY)
|
||||
val retryDelay = if (e is TooManyRequestExceptions) {
|
||||
e.retryAfter + DOWNLOAD_ERROR_DELAY
|
||||
} else {
|
||||
DOWNLOAD_ERROR_DELAY
|
||||
}
|
||||
delay(retryDelay)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user