Skip to content

Commit 35fd507

Browse files
committed
feat(MyKSuite): Fail silently if the ksuite call fails
1 parent 92dcfe7 commit 35fd507

File tree

2 files changed

+15
-10
lines changed

2 files changed

+15
-10
lines changed

app/src/main/java/com/infomaniak/mail/ui/MainViewModel.kt

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -339,17 +339,22 @@ class MainViewModel @Inject constructor(
339339
}
340340

341341
private suspend fun updateMyKSuiteData() {
342-
MyKSuiteDataUtils.requestKSuiteData()
343-
val apiResponse = ApiRepository.getMyKSuiteData(HttpClient.okHttpClient)
344-
if (apiResponse.data != null) {
345-
MyKSuiteDataUtils.upsertKSuiteData(apiResponse.data!!)
346-
} else {
347-
@OptIn(ExperimentalSerializationApi::class)
348-
apiResponse.error?.exception?.let {
349-
if (it is MissingFieldException || it.message?.contains("Unexpected JSON token") == true) {
350-
SentryLog.e(TAG, "Error decoding the api result MyKSuiteObject", it)
342+
runCatching {
343+
MyKSuiteDataUtils.requestKSuiteData()
344+
val apiResponse = ApiRepository.getMyKSuiteData(HttpClient.okHttpClient)
345+
if (apiResponse.data != null) {
346+
MyKSuiteDataUtils.upsertKSuiteData(apiResponse.data!!)
347+
} else {
348+
@OptIn(ExperimentalSerializationApi::class)
349+
apiResponse.error?.exception?.let {
350+
if (it is MissingFieldException || it.message?.contains("Unexpected JSON token") == true) {
351+
SentryLog.e(TAG, "Error decoding the api result MyKSuiteObject", it)
352+
}
351353
}
352354
}
355+
}.onFailure { exception ->
356+
if (exception is CancellationException) throw exception
357+
SentryLog.d(TAG, "Exception during myKSuite data fetch", exception)
353358
}
354359
}
355360

0 commit comments

Comments
 (0)