From 7a4d9370e34f9df26121ee9a8870b26802832dd1 Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Mon, 11 May 2020 15:32:04 +0200 Subject: [PATCH] Identity: human readable errors --- .../api/session/identity/IdentityServiceError.kt | 16 ++++++++-------- .../im/vector/riotx/core/error/ErrorFormatter.kt | 14 ++++++++++++++ .../change/SetIdentityServerViewModel.kt | 2 +- vector/src/main/res/values/strings.xml | 9 ++++++++- 4 files changed, 31 insertions(+), 10 deletions(-) diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/identity/IdentityServiceError.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/identity/IdentityServiceError.kt index b4d7a0e0b7..83fb949946 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/identity/IdentityServiceError.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/identity/IdentityServiceError.kt @@ -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() } diff --git a/vector/src/main/java/im/vector/riotx/core/error/ErrorFormatter.kt b/vector/src/main/java/im/vector/riotx/core/error/ErrorFormatter.kt index 557bc93bb1..57e5c6381f 100644 --- a/vector/src/main/java/im/vector/riotx/core/error/ErrorFormatter.kt +++ b/vector/src/main/java/im/vector/riotx/core/error/ErrorFormatter.kt @@ -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 + }) + } } diff --git a/vector/src/main/java/im/vector/riotx/features/discovery/change/SetIdentityServerViewModel.kt b/vector/src/main/java/im/vector/riotx/features/discovery/change/SetIdentityServerViewModel.kt index 88a1bc5ac8..386cd7be30 100644 --- a/vector/src/main/java/im/vector/riotx/features/discovery/change/SetIdentityServerViewModel.kt +++ b/vector/src/main/java/im/vector/riotx/features/discovery/change/SetIdentityServerViewModel.kt @@ -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 } diff --git a/vector/src/main/res/values/strings.xml b/vector/src/main/res/values/strings.xml index 5a4c200a2d..6aced9af7f 100644 --- a/vector/src/main/res/values/strings.xml +++ b/vector/src/main/res/values/strings.xml @@ -1738,7 +1738,6 @@ Not all features in Riot are implemented in RiotX yet. Main missing (and coming Enter a new identity server Could not connect to identity server - This identity server does not support API V2 Please enter the identity server url Identity server has no terms of services The identity server you have chosen does not have any terms of services. Only continue if you trust the owner of the service @@ -2405,4 +2404,12 @@ Not all features in Riot are implemented in RiotX yet. Main missing (and coming Open terms of %s Disconnect from the identity server %s? + This identity server is outdated. RiotX support only API V2. + This operation is not possible. The homeserver is outdated. + Please first configure an identity server. + Please first accepts the terms of the identity server in the settings. + For your privacy, RiotX only supports sending hashed user emails and phone number. + The association has failed. + The is no current association with this identifier. +