Skip to content

Commit

Permalink
Sync HAPI FHIR Exceptions Logging for the FHIR SDK
Browse files Browse the repository at this point in the history
  • Loading branch information
ndegwamartin committed Sep 4, 2024
1 parent 4eb2ca2 commit 3e8fdb5
Showing 1 changed file with 18 additions and 18 deletions.
36 changes: 18 additions & 18 deletions engine/src/main/java/com/google/android/fhir/sync/FhirSyncWorker.kt
Original file line number Diff line number Diff line change
Expand Up @@ -164,26 +164,26 @@ abstract class FhirSyncWorker(appContext: Context, workerParams: WorkerParameter

open fun onFailedSyncJobResult(failedSyncJobStatus: SyncJobStatus.Failed) {
try {
CoroutineScope(Dispatchers.IO).launch {
val jsonParser = FhirContext.forR4().newJsonParser()

(failedSyncJobStatus).exceptions.filterIsInstance<HttpException>().forEach {
resourceSyncHTTPException ->
val operationOutcome =
jsonParser.parseResource(
IOUtils.toString(
resourceSyncHTTPException.response()?.errorBody()?.byteStream(),
StandardCharsets.UTF_8,
),
) as OperationOutcome

operationOutcome.issue.forEach { operationOutcome ->
Timber.e(
"SERVER ${operationOutcome.severity} - HTTP ${resourceSyncHTTPException.code()} | Code - ${operationOutcome.code} | Diagnostics - ${operationOutcome.diagnostics}",
)
}

val jsonParser = FhirContext.forR4().newJsonParser()
val exceptions = (failedSyncJobStatus).exceptions

exceptions.forEach{ resourceSyncException ->
val operationOutcome =
jsonParser.parseResource(
IOUtils.toString(
(resourceSyncException.exception as HttpException).response()?.errorBody()?.byteStream(),
StandardCharsets.UTF_8,
),
) as OperationOutcome

operationOutcome.issue.forEach { operationOutcome ->
Timber.e(
"SERVER ${operationOutcome.severity} - HTTP ${resourceSyncException.exception.code()} | Code - ${operationOutcome.code} | Diagnostics - ${operationOutcome.diagnostics}",
)
}
}

} catch (e: Exception) {
Timber.e(e)
}
Expand Down

0 comments on commit 3e8fdb5

Please sign in to comment.