mirror of
https://github.com/SchildiChat/SchildiChat-android.git
synced 2024-11-26 19:36:08 +03:00
Improve M_LIMIT_EXCEEDED error rendering
This commit is contained in:
parent
af45c554fd
commit
8de1fa835b
3 changed files with 21 additions and 2 deletions
|
@ -31,7 +31,9 @@ data class MatrixError(
|
|||
@Json(name = "consent_uri") val consentUri: String? = null,
|
||||
// RESOURCE_LIMIT_EXCEEDED data
|
||||
@Json(name = "limit_type") val limitType: String? = null,
|
||||
@Json(name = "admin_contact") val adminUri: String? = null) {
|
||||
@Json(name = "admin_contact") val adminUri: String? = null,
|
||||
// For LIMIT_EXCEEDED
|
||||
@Json(name = "retry_after_ms") val retryAfterMillis: Long? = null) {
|
||||
|
||||
companion object {
|
||||
const val FORBIDDEN = "M_FORBIDDEN"
|
||||
|
|
|
@ -65,7 +65,7 @@ class ErrorFormatter @Inject constructor(private val stringProvider: StringProvi
|
|||
stringProvider.getString(R.string.login_error_not_json)
|
||||
}
|
||||
throwable.error.code == MatrixError.LIMIT_EXCEEDED -> {
|
||||
stringProvider.getString(R.string.login_error_limit_exceeded)
|
||||
limitExceededError(throwable.error)
|
||||
}
|
||||
throwable.error.code == MatrixError.THREEPID_NOT_FOUND -> {
|
||||
stringProvider.getString(R.string.login_reset_password_error_not_found)
|
||||
|
@ -80,4 +80,16 @@ class ErrorFormatter @Inject constructor(private val stringProvider: StringProvi
|
|||
}
|
||||
?: stringProvider.getString(R.string.unknown_error)
|
||||
}
|
||||
|
||||
private fun limitExceededError(error: MatrixError): String {
|
||||
val delay = error.retryAfterMillis
|
||||
|
||||
return if (delay == null) {
|
||||
stringProvider.getString(R.string.login_error_limit_exceeded)
|
||||
} else {
|
||||
// Ensure at least 1 second
|
||||
val delaySeconds = delay.toInt() / 1000 + 1
|
||||
stringProvider.getQuantityString(R.plurals.login_error_limit_exceeded_retry_after, delaySeconds, delaySeconds)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -128,4 +128,9 @@
|
|||
<string name="login_wait_for_email_notice">We just sent an email to %1$s.\nPlease click on the link it contains to continue the account creation.</string>
|
||||
<string name="login_validation_code_is_not_correct">The entered code is not correct. Please check.</string>
|
||||
|
||||
<plurals name="login_error_limit_exceeded_retry_after">
|
||||
<item quantity="one">Too many requests have been sent. You can retry in %1$d second…</item>
|
||||
<item quantity="other">Too many requests have been sent. You can retry in %1$d seconds…</item>
|
||||
</plurals>
|
||||
|
||||
</resources>
|
||||
|
|
Loading…
Reference in a new issue