From 7e87ad438475cb367cd52fd58f2d1987f80912b2 Mon Sep 17 00:00:00 2001 From: Avently <7953703+avently@users.noreply.github.com> Date: Wed, 14 Dec 2022 16:03:16 +0300 Subject: [PATCH] android: Show error instead of crashing after failed to parse chats --- .../src/main/java/chat/simplex/app/model/SimpleXAPI.kt | 9 ++++++--- apps/android/app/src/main/res/values/strings.xml | 3 +++ 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/apps/android/app/src/main/java/chat/simplex/app/model/SimpleXAPI.kt b/apps/android/app/src/main/java/chat/simplex/app/model/SimpleXAPI.kt index 440cfb4ebf..404b3dcde9 100644 --- a/apps/android/app/src/main/java/chat/simplex/app/model/SimpleXAPI.kt +++ b/apps/android/app/src/main/java/chat/simplex/app/model/SimpleXAPI.kt @@ -404,14 +404,17 @@ open class ChatController(var ctrl: ChatCtrl?, val ntfManager: NtfManager, val a suspend fun apiGetChats(): List { val r = sendCmd(CC.ApiGetChats()) - if (r is CR.ApiChats ) return r.chats - throw Exception("failed getting the list of chats: ${r.responseType} ${r.details}") + if (r is CR.ApiChats) return r.chats + Log.e(TAG, "failed getting the list of chats: ${r.responseType} ${r.details}") + AlertManager.shared.showAlertMsg(generalGetString(R.string.failed_to_parse_chats_title), generalGetString(R.string.contact_developers)) + return emptyList() } suspend fun apiGetChat(type: ChatType, id: Long, pagination: ChatPagination = ChatPagination.Last(ChatPagination.INITIAL_COUNT), search: String = ""): Chat? { val r = sendCmd(CC.ApiGetChat(type, id, pagination, search)) - if (r is CR.ApiChat ) return r.chat + if (r is CR.ApiChat) return r.chat Log.e(TAG, "apiGetChat bad response: ${r.responseType} ${r.details}") + AlertManager.shared.showAlertMsg(generalGetString(R.string.failed_to_parse_chat_title), generalGetString(R.string.contact_developers)) return null } diff --git a/apps/android/app/src/main/res/values/strings.xml b/apps/android/app/src/main/res/values/strings.xml index bb3bb545ca..45542a5908 100644 --- a/apps/android/app/src/main/res/values/strings.xml +++ b/apps/android/app/src/main/res/values/strings.xml @@ -57,6 +57,9 @@ Error saving SMP servers Make sure SMP server addresses are in correct format, line separated and are not duplicated. Error updating network configuration + Failed to parse chat + Failed to parse chats list + Please, contact developers or update the app Connection timeout