Identity: human readable errors

This commit is contained in:
Benoit Marty 2020-05-11 15:32:04 +02:00
parent fe3138492e
commit 7a4d9370e3
4 changed files with 31 additions and 10 deletions

View File

@ -16,12 +16,12 @@
package im.vector.matrix.android.api.session.identity
sealed class IdentityServiceError(cause: Throwable? = null) : Throwable(cause = cause) {
object OutdatedIdentityServer : IdentityServiceError(null)
object OutdatedHomeServer : IdentityServiceError(null)
object NoIdentityServerConfigured : IdentityServiceError(null)
object TermsNotSignedException : IdentityServiceError(null)
object BulkLookupSha256NotSupported : IdentityServiceError(null)
object BindingError : IdentityServiceError(null)
object NoCurrentBindingError : IdentityServiceError(null)
sealed class IdentityServiceError : Throwable() {
object OutdatedIdentityServer : IdentityServiceError()
object OutdatedHomeServer : IdentityServiceError()
object NoIdentityServerConfigured : IdentityServiceError()
object TermsNotSignedException : IdentityServiceError()
object BulkLookupSha256NotSupported : IdentityServiceError()
object BindingError : IdentityServiceError()
object NoCurrentBindingError : IdentityServiceError()
}

View File

@ -19,6 +19,7 @@ package im.vector.riotx.core.error
import im.vector.matrix.android.api.failure.Failure
import im.vector.matrix.android.api.failure.MatrixError
import im.vector.matrix.android.api.failure.isInvalidPassword
import im.vector.matrix.android.api.session.identity.IdentityServiceError
import im.vector.riotx.R
import im.vector.riotx.core.resources.StringProvider
import java.net.HttpURLConnection
@ -37,6 +38,7 @@ class DefaultErrorFormatter @Inject constructor(
override fun toHumanReadable(throwable: Throwable?): String {
return when (throwable) {
null -> null
is IdentityServiceError -> identityServerError(throwable)
is Failure.NetworkConnection -> {
when {
throwable.ioException is SocketTimeoutException ->
@ -107,4 +109,16 @@ class DefaultErrorFormatter @Inject constructor(
stringProvider.getQuantityString(R.plurals.login_error_limit_exceeded_retry_after, delaySeconds, delaySeconds)
}
}
private fun identityServerError(identityServiceError: IdentityServiceError): String {
return stringProvider.getString(when (identityServiceError) {
IdentityServiceError.OutdatedIdentityServer -> R.string.identity_server_error_outdated_identity_server
IdentityServiceError.OutdatedHomeServer -> R.string.identity_server_error_outdated_home_server
IdentityServiceError.NoIdentityServerConfigured -> R.string.identity_server_error_no_identity_server_configured
IdentityServiceError.TermsNotSignedException -> R.string.identity_server_error_terms_not_signed
IdentityServiceError.BulkLookupSha256NotSupported -> R.string.identity_server_error_bulk_sha256_not_supported
IdentityServiceError.BindingError -> R.string.identity_server_error_binding_error
IdentityServiceError.NoCurrentBindingError -> R.string.identity_server_error_no_current_binding_error
})
}
}

View File

@ -102,7 +102,7 @@ class SetIdentityServerViewModel @AssistedInject constructor(
copy(
isVerifyingServer = false,
errorMessageId = if (failure is IdentityServiceError.OutdatedIdentityServer) {
R.string.settings_discovery_outdated_identity_server
R.string.identity_server_error_outdated_identity_server
} else {
R.string.settings_discovery_bad_identity_server
}

View File

@ -1738,7 +1738,6 @@ Not all features in Riot are implemented in RiotX yet. Main missing (and coming
<string name="settings_discovery_enter_identity_server">Enter a new identity server</string>
<string name="settings_discovery_bad_identity_server">Could not connect to identity server</string>
<string name="settings_discovery_outdated_identity_server">This identity server does not support API V2</string>
<string name="settings_discovery_please_enter_server">Please enter the identity server url</string>
<string name="settings_discovery_no_terms_title">Identity server has no terms of services</string>
<string name="settings_discovery_no_terms">The identity server you have chosen does not have any terms of services. Only continue if you trust the owner of the service</string>
@ -2405,4 +2404,12 @@ Not all features in Riot are implemented in RiotX yet. Main missing (and coming
<string name="open_terms_of">Open terms of %s</string>
<string name="disconnect_identity_server_dialog_content">Disconnect from the identity server %s?</string>
<string name="identity_server_error_outdated_identity_server">This identity server is outdated. RiotX support only API V2.</string>
<string name="identity_server_error_outdated_home_server">This operation is not possible. The homeserver is outdated.</string>
<string name="identity_server_error_no_identity_server_configured">Please first configure an identity server.</string>
<string name="identity_server_error_terms_not_signed">Please first accepts the terms of the identity server in the settings.</string>
<string name="identity_server_error_bulk_sha256_not_supported">For your privacy, RiotX only supports sending hashed user emails and phone number.</string>
<string name="identity_server_error_binding_error">The association has failed.</string>
<string name="identity_server_error_no_current_binding_error">The is no current association with this identifier.</string>
</resources>