From 77eb7cca0f43da29369299b1d3793f595d0d3280 Mon Sep 17 00:00:00 2001 From: sowjanyakch Date: Tue, 12 Nov 2024 17:37:40 +0100 Subject: [PATCH] handle errors Signed-off-by: sowjanyakch --- .../talk/settings/SettingsActivity.kt | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/com/nextcloud/talk/settings/SettingsActivity.kt b/app/src/main/java/com/nextcloud/talk/settings/SettingsActivity.kt index adb4183bd4..99bac3ba3f 100644 --- a/app/src/main/java/com/nextcloud/talk/settings/SettingsActivity.kt +++ b/app/src/main/java/com/nextcloud/talk/settings/SettingsActivity.kt @@ -91,6 +91,7 @@ import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.launch import okhttp3.MediaType.Companion.toMediaTypeOrNull import okhttp3.RequestBody.Companion.toRequestBody +import retrofit2.HttpException import java.net.URI import java.net.URISyntaxException import java.util.Locale @@ -1291,11 +1292,16 @@ class SettingsActivity : BaseActivity(), SetPhoneNumberDialogFragment.SetPhoneNu ApiUtils.getUrlForUserSettings(currentUser!!.baseUrl!!), json.toRequestBody("application/json".toMediaTypeOrNull()) ) + Log.i(TAG, "reading status set") } - Log.i(TAG, "reading status set") } catch (e: Exception) { appPreferences.setReadPrivacy(!newBoolean) binding.settingsReadPrivacySwitch.isChecked = !newBoolean + if (e is HttpException && e.code() == HTTP_ERROR_CODE_BAD_REQUEST) { + Log.e(TAG, "read_status_privacy : Key or value is invalid") + } else { + Log.e(TAG, "Error updating read status", e) + } } } } @@ -1318,13 +1324,17 @@ class SettingsActivity : BaseActivity(), SetPhoneNumberDialogFragment.SetPhoneNu ApiUtils.getUrlForUserSettings(currentUser!!.baseUrl!!), json.toRequestBody("application/json".toMediaTypeOrNull()) ) + loadCapabilitiesAndUpdateSettings() + Log.i(TAG, "typing status set") } - - loadCapabilitiesAndUpdateSettings() - Log.i(TAG, "typing status set") } catch (e: Exception) { appPreferences.typingStatus = !newBoolean binding.settingsTypingStatusSwitch.isChecked = !newBoolean + if (e is HttpException && e.code() == HTTP_ERROR_CODE_BAD_REQUEST) { + Log.e(TAG, "typing_privacy : Key or value is invalid") + } else { + Log.e(TAG, "Error updating typing status", e) + } } } } @@ -1338,5 +1348,6 @@ class SettingsActivity : BaseActivity(), SetPhoneNumberDialogFragment.SetPhoneNu private const val DISABLED_ALPHA: Float = 0.38f private const val ENABLED_ALPHA: Float = 1.0f const val HTTP_CODE_OK: Int = 200 + const val HTTP_ERROR_CODE_BAD_REQUEST: Int = 400 } }