From 3739e50d466d8e38ced20b64d2dfb8385ee4e253 Mon Sep 17 00:00:00 2001
From: Benoit Marty <benoit@matrix.org>
Date: Thu, 12 Sep 2019 16:59:00 +0200
Subject: [PATCH] Better error message for timeout

---
 .../java/im/vector/riotx/core/error/ErrorFormatter.kt    | 9 ++++++++-
 vector/src/main/res/values/strings_riotX.xml             | 1 +
 2 files changed, 9 insertions(+), 1 deletion(-)

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 bb7892e109..8987b0260a 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
@@ -20,6 +20,7 @@ import im.vector.matrix.android.api.failure.Failure
 import im.vector.matrix.android.api.failure.MatrixError
 import im.vector.riotx.R
 import im.vector.riotx.core.resources.StringProvider
+import java.net.SocketTimeoutException
 import javax.inject.Inject
 
 class ErrorFormatter @Inject constructor(val stringProvider: StringProvider) {
@@ -33,7 +34,13 @@ class ErrorFormatter @Inject constructor(val stringProvider: StringProvider) {
     fun toHumanReadable(throwable: Throwable?): String {
         return when (throwable) {
             null                         -> null
-            is Failure.NetworkConnection -> stringProvider.getString(R.string.error_no_network)
+            is Failure.NetworkConnection -> {
+                if (throwable.ioException is SocketTimeoutException) {
+                    stringProvider.getString(R.string.error_network_timeout)
+                } else {
+                    stringProvider.getString(R.string.error_no_network)
+                }
+            }
             is Failure.ServerError       -> {
                 if (throwable.error.code == MatrixError.M_CONSENT_NOT_GIVEN) {
                     // Special case for terms and conditions
diff --git a/vector/src/main/res/values/strings_riotX.xml b/vector/src/main/res/values/strings_riotX.xml
index e02de69806..f2ac7817be 100644
--- a/vector/src/main/res/values/strings_riotX.xml
+++ b/vector/src/main/res/values/strings_riotX.xml
@@ -11,5 +11,6 @@
     <!-- This one is already defined in Riot, but not yet synced-->
     <string name="error_user_already_logged_in">It looks like you’re trying to connect to another homeserver. Do you want to sign out?</string>
 
+    <string name="error_network_timeout">Looks like the server is taking to long to respond, this can be caused by either poor connectivity or an error with our servers. Please try again in a while.</string>
 
 </resources>
\ No newline at end of file