From dd04ef0f2464a4b6413b7dbc4ee316ac39c78705 Mon Sep 17 00:00:00 2001 From: Kolya Opahle <k.opahle@sap.com> Date: Wed, 16 Jun 2021 16:57:00 +0200 Subject: [PATCH] Cannot obtain test certificate after deleting pending/failed test certificate (EXPOSUREAPP-7763) (#3474) Remove catch clause from flow as this would cancel it and replace it with a try catch in the on each callback Co-authored-by: harambasicluka <64483219+harambasicluka@users.noreply.github.com> --- .../TestCertificateRetrievalScheduler.kt | 23 +++++++++++-------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/covidcertificate/test/core/execution/TestCertificateRetrievalScheduler.kt b/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/covidcertificate/test/core/execution/TestCertificateRetrievalScheduler.kt index 2ad3ee645..02e1e616f 100644 --- a/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/covidcertificate/test/core/execution/TestCertificateRetrievalScheduler.kt +++ b/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/covidcertificate/test/core/execution/TestCertificateRetrievalScheduler.kt @@ -14,7 +14,6 @@ import de.rki.coronawarnapp.util.device.ForegroundState import de.rki.coronawarnapp.util.flow.combine import de.rki.coronawarnapp.worker.BackgroundConstants import kotlinx.coroutines.CoroutineScope -import kotlinx.coroutines.flow.catch import kotlinx.coroutines.flow.distinctUntilChanged import kotlinx.coroutines.flow.launchIn import kotlinx.coroutines.flow.map @@ -30,7 +29,7 @@ class TestCertificateRetrievalScheduler @Inject constructor( private val workManager: WorkManager, private val certificateRepo: TestCertificateRepository, private val testRepo: CoronaTestRepository, - private val foregroundState: ForegroundState, + foregroundState: ForegroundState, ) : ResultScheduler( workManager = workManager ) { @@ -69,21 +68,27 @@ class TestCertificateRetrievalScheduler @Inject constructor( .onEach { testsWithoutCert -> Timber.tag(TAG).d("State change: testsWithoutCert=$testsWithoutCert") testsWithoutCert.forEach { test -> - val cert = certificateRepo.requestCertificate(test) - Timber.tag(TAG).v("Certificate was created: %s", cert) - testRepo.markDccAsCreated(test.identifier, created = true) + try { + val cert = certificateRepo.requestCertificate(test) + Timber.tag(TAG).v("Certificate was created: %s", cert) + testRepo.markDccAsCreated(test.identifier, created = true) + } catch (e: Exception) { + Timber.tag(TAG).e(e, "Creation trigger failed.") + } } } - .catch { Timber.tag(TAG).e(it, "Creation trigger failed.") } .launchIn(appScope) // For each change to the set of existing certificates, check if we need to refresh/load data refreshTrigger .onEach { checkCerts -> - Timber.tag(TAG).d("State change: checkCerts=$checkCerts") - if (checkCerts) scheduleWorker() + try { + Timber.tag(TAG).d("State change: checkCerts=$checkCerts") + if (checkCerts) scheduleWorker() + } catch (e: Exception) { + Timber.tag(TAG).e(e, "Refresh trigger failed.") + } } - .catch { Timber.tag(TAG).e(it, "Refresh trigger failed.") } .launchIn(appScope) } -- GitLab