From 27ba2acf869188e7d833b96cc53b50bbacc83bd5 Mon Sep 17 00:00:00 2001
From: Marcel Hibbe <dev@mhibbe.de>
Date: Wed, 4 Jun 2025 13:10:42 +0200
Subject: [PATCH] catch http 405 if endpoint is not available.

E.g. for older server versions

Without this fix there would be the crash:

 E  FATAL EXCEPTION: main
 Process: com.nextcloud.talk2, PID: 7161
  retrofit2.HttpException: HTTP 405
  at retrofit2.KotlinExtensions$await$2$2.onResponse(KotlinExtensions.kt:53)
  at retrofit2.OkHttpCall$1.onResponse(OkHttpCall.java:164)
  at okhttp3.internal.connection.RealCall$AsyncCall.run(RealCall.kt:519)
  at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
  at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:644)
  at java.lang.Thread.run(Thread.java:1012)
Suppressed: kotlinx.coroutines.internal.DiagnosticCoroutineContextException: [StandaloneCoroutine{Cancelling}@4a67b41, Dispatchers.Main.immediate]

Signed-off-by: Marcel Hibbe <dev@mhibbe.de>
---
 .../viewmodel/ConversationInfoViewModel.kt        | 15 ++++++++++-----
 1 file changed, 10 insertions(+), 5 deletions(-)

diff --git a/app/src/main/java/com/nextcloud/talk/conversationinfo/viewmodel/ConversationInfoViewModel.kt b/app/src/main/java/com/nextcloud/talk/conversationinfo/viewmodel/ConversationInfoViewModel.kt
index 1c2da4000..cb4bc7c3f 100644
--- a/app/src/main/java/com/nextcloud/talk/conversationinfo/viewmodel/ConversationInfoViewModel.kt
+++ b/app/src/main/java/com/nextcloud/talk/conversationinfo/viewmodel/ConversationInfoViewModel.kt
@@ -319,14 +319,19 @@ class ConversationInfoViewModel @Inject constructor(
         }
     }
 
+    @Suppress("Detekt.TooGenericExceptionCaught")
     fun getProfileData(user: User, userId: String) {
         val url = ApiUtils.getUrlForProfile(user.baseUrl!!, userId)
         viewModelScope.launch {
-            val profile = conversationsRepository.getProfile(user.getCredentials(), url)
-            if (profile != null) {
-                _getProfileViewState.value = GetProfileSuccessState(profile)
-            } else {
-                _getProfileViewState.value = GetProfileErrorState
+            try {
+                val profile = conversationsRepository.getProfile(user.getCredentials(), url)
+                if (profile != null) {
+                    _getProfileViewState.value = GetProfileSuccessState(profile)
+                } else {
+                    _getProfileViewState.value = GetProfileErrorState
+                }
+            } catch (e: Exception) {
+                Log.w(TAG, "Failed to get profile data (if not supported there wil be http405)", e)
             }
         }
     }