From e926326fcafd1bfeaf09a01dd491b7078e25e536 Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Fri, 2 Oct 2020 15:32:29 +0200 Subject: [PATCH] Better handling of network error. Entering a wrong homeserver URL is now a specific error. --- .../java/im/vector/app/core/error/ErrorFormatter.kt | 5 +---- .../app/features/login/LoginServerUrlFormFragment.kt | 10 +++++++++- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/vector/src/main/java/im/vector/app/core/error/ErrorFormatter.kt b/vector/src/main/java/im/vector/app/core/error/ErrorFormatter.kt index 43395b97f7..790f19a133 100644 --- a/vector/src/main/java/im/vector/app/core/error/ErrorFormatter.kt +++ b/vector/src/main/java/im/vector/app/core/error/ErrorFormatter.kt @@ -45,15 +45,12 @@ class DefaultErrorFormatter @Inject constructor( when (throwable.ioException) { is SocketTimeoutException -> stringProvider.getString(R.string.error_network_timeout) - is UnknownHostException -> - // Invalid homeserver? - // TODO Check network state, airplane mode, etc. - stringProvider.getString(R.string.login_error_unknown_host) is SSLPeerUnverifiedException -> stringProvider.getString(R.string.login_error_ssl_peer_unverified) is SSLException -> stringProvider.getString(R.string.login_error_ssl_other) else -> + // TODO Check network state, airplane mode, etc. stringProvider.getString(R.string.error_no_network) } } diff --git a/vector/src/main/java/im/vector/app/features/login/LoginServerUrlFormFragment.kt b/vector/src/main/java/im/vector/app/features/login/LoginServerUrlFormFragment.kt index 4b9f528254..af959fecd4 100644 --- a/vector/src/main/java/im/vector/app/features/login/LoginServerUrlFormFragment.kt +++ b/vector/src/main/java/im/vector/app/features/login/LoginServerUrlFormFragment.kt @@ -28,6 +28,8 @@ import im.vector.app.core.extensions.hideKeyboard import im.vector.app.core.utils.ensureProtocol import im.vector.app.core.utils.openUrlInChromeCustomTab import kotlinx.android.synthetic.main.fragment_login_server_url_form.* +import org.matrix.android.sdk.api.failure.Failure +import java.net.UnknownHostException import javax.inject.Inject /** @@ -115,7 +117,13 @@ class LoginServerUrlFormFragment @Inject constructor() : AbstractLoginFragment() } override fun onError(throwable: Throwable) { - loginServerUrlFormHomeServerUrlTil.error = errorFormatter.toHumanReadable(throwable) + loginServerUrlFormHomeServerUrlTil.error = if (throwable is Failure.NetworkConnection + && throwable.ioException is UnknownHostException) { + // Invalid homeserver? + getString(R.string.login_error_homeserver_not_found) + } else { + errorFormatter.toHumanReadable(throwable) + } } override fun updateWithState(state: LoginViewState) {