Skip to content

Commit

Permalink
Fix sync state exception handling
Browse files Browse the repository at this point in the history
  • Loading branch information
Rkareko committed Nov 24, 2023
1 parent acccecf commit 09a637c
Showing 1 changed file with 14 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.flow
import org.hl7.fhir.r4.model.Resource
import org.hl7.fhir.r4.model.ResourceType
import timber.log.Timber

/** Implementation of [FhirEngine]. */
internal class FhirEngineImpl(private val database: Database, private val context: Context) :
Expand Down Expand Up @@ -90,15 +91,19 @@ internal class FhirEngineImpl(private val database: Database, private val contex
download: suspend () -> Flow<List<Resource>>,
) {
download().collect { resources ->
database.withTransaction {
val resolved =
resolveConflictingResources(
resources,
getConflictingResourceIds(resources),
conflictResolver,
)
database.insertSyncedResources(resources)
saveResolvedResourcesToDatabase(resolved)
try {
database.withTransaction {
val resolved =
resolveConflictingResources(
resources,
getConflictingResourceIds(resources),
conflictResolver,
)
database.insertSyncedResources(resources)
saveResolvedResourcesToDatabase(resolved)
}
} catch (exception: Exception) {
Timber.e(exception, "Error encountered while inserting synced resources")
}
}
}
Expand Down

0 comments on commit 09a637c

Please sign in to comment.