mirror of
https://github.com/vector-im/element-android.git
synced 2024-11-15 01:35:07 +08:00
Always try to retry Http requests in case of 429 (#1300)
This commit is contained in:
parent
9b5bc60fa9
commit
8dead986a5
@ -18,6 +18,7 @@ Improvements 🙌:
|
||||
- Room list improvements (paging)
|
||||
- Fix quick click action (#3127)
|
||||
- Get Event after a Push for a faster notification display in some conditions
|
||||
- Always try to retry Http requests in case of 429 (#1300)
|
||||
|
||||
Bugfix 🐛:
|
||||
- Fix bad theme change for the MainActivity
|
||||
|
@ -19,6 +19,7 @@ package org.matrix.android.sdk.internal.network
|
||||
import kotlinx.coroutines.CancellationException
|
||||
import kotlinx.coroutines.delay
|
||||
import org.matrix.android.sdk.api.failure.Failure
|
||||
import org.matrix.android.sdk.api.failure.MatrixError
|
||||
import org.matrix.android.sdk.api.failure.getRetryDelay
|
||||
import org.matrix.android.sdk.api.failure.shouldBeRetried
|
||||
import org.matrix.android.sdk.internal.network.ssl.CertUtil
|
||||
@ -71,9 +72,16 @@ internal suspend inline fun <DATA> executeRequest(globalErrorReceiver: GlobalErr
|
||||
// }
|
||||
?.also { unrecognizedCertificateException -> throw unrecognizedCertificateException }
|
||||
|
||||
if (canRetry && currentRetryCount++ < maxRetriesCount && exception.shouldBeRetried()) {
|
||||
// In case of 429, ensure we wait enough
|
||||
delay(currentDelay.coerceAtLeast(exception.getRetryDelay(0)))
|
||||
currentRetryCount++
|
||||
|
||||
if (exception is Failure.ServerError
|
||||
&& exception.httpCode == 429
|
||||
&& exception.error.code == MatrixError.M_LIMIT_EXCEEDED
|
||||
&& currentRetryCount < maxRetriesCount) {
|
||||
// 429, we can retry
|
||||
delay(exception.getRetryDelay(1_000))
|
||||
} else if (canRetry && currentRetryCount < maxRetriesCount && exception.shouldBeRetried()) {
|
||||
delay(currentDelay)
|
||||
currentDelay = currentDelay.times(2L).coerceAtMost(maxDelayBeforeRetry)
|
||||
// Try again (loop)
|
||||
} else {
|
||||
|
Loading…
Reference in New Issue
Block a user