From 1b33c03d9179d6aff7f17f3efff1ec2acb8033bc Mon Sep 17 00:00:00 2001 From: Adam Brown Date: Thu, 14 Apr 2022 12:01:23 +0100 Subject: [PATCH] lifting unavailable homeserver condition to the other error types --- .../org/matrix/android/sdk/api/failure/Extensions.kt | 6 ++++++ .../FtueAuthCombinedServerSelectionFragment.kt | 11 ++++------- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/failure/Extensions.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/failure/Extensions.kt index 99fc0ba8b7..462c0cd638 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/failure/Extensions.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/failure/Extensions.kt @@ -22,6 +22,7 @@ import org.matrix.android.sdk.api.session.contentscanner.ContentScannerError import org.matrix.android.sdk.api.session.contentscanner.ScanFailure import org.matrix.android.sdk.internal.di.MoshiProvider import java.io.IOException +import java.net.UnknownHostException import javax.net.ssl.HttpsURLConnection fun Throwable.is401() = @@ -99,6 +100,11 @@ fun Throwable.isInvalidUIAAuth(): Boolean { error.flows != null } +fun Throwable.isHomeserverUnavailable(): Boolean { + return this is Failure.NetworkConnection && + this.ioException is UnknownHostException +} + /** * Try to convert to a RegistrationFlowResponse. Return null in the cases it's not possible */ diff --git a/vector/src/main/java/im/vector/app/features/onboarding/ftueauth/FtueAuthCombinedServerSelectionFragment.kt b/vector/src/main/java/im/vector/app/features/onboarding/ftueauth/FtueAuthCombinedServerSelectionFragment.kt index 97e2db2123..2e6057288a 100644 --- a/vector/src/main/java/im/vector/app/features/onboarding/ftueauth/FtueAuthCombinedServerSelectionFragment.kt +++ b/vector/src/main/java/im/vector/app/features/onboarding/ftueauth/FtueAuthCombinedServerSelectionFragment.kt @@ -36,9 +36,8 @@ import im.vector.app.features.onboarding.OnboardingViewEvents import im.vector.app.features.onboarding.OnboardingViewState import kotlinx.coroutines.flow.launchIn import kotlinx.coroutines.flow.onEach -import org.matrix.android.sdk.api.failure.Failure +import org.matrix.android.sdk.api.failure.isHomeserverUnavailable import reactivecircus.flowbinding.android.widget.textChanges -import java.net.UnknownHostException import javax.inject.Inject class FtueAuthCombinedServerSelectionFragment @Inject constructor() : AbstractFtueAuthFragment() { @@ -88,11 +87,9 @@ class FtueAuthCombinedServerSelectionFragment @Inject constructor() : AbstractFt } override fun onError(throwable: Throwable) { - views.chooseServerInput.error = if (throwable is Failure.NetworkConnection && - throwable.ioException is UnknownHostException) { - getString(R.string.login_error_homeserver_not_found) - } else { - errorFormatter.toHumanReadable(throwable) + views.chooseServerInput.error = when { + throwable.isHomeserverUnavailable() -> getString(R.string.login_error_homeserver_not_found) + else -> errorFormatter.toHumanReadable(throwable) } }