Skip to content

Commit

Permalink
Catch and log non-HAPI FHIR Exceptions
Browse files Browse the repository at this point in the history
  • Loading branch information
ndegwamartin committed Dec 2, 2024
1 parent 59b4ff4 commit 846a085
Showing 1 changed file with 16 additions and 15 deletions.
31 changes: 16 additions & 15 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,21 +164,22 @@ abstract class FhirSyncWorker(appContext: Context, workerParams: WorkerParameter

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

operationOutcome.issue.forEach { operationOutcomeIssueComponent ->
Timber.e(
"SERVER ${operationOutcomeIssueComponent.severity} - HTTP ${resourceSyncException.exception.code()} | Code - ${operationOutcomeIssueComponent.code} | Diagnostics - ${operationOutcomeIssueComponent.diagnostics}",
)
if (resourceSyncException.exception is HttpException) {
val operationOutcome =
jsonParser.parseResource(
IOUtils.toString(
resourceSyncException.exception.response()?.errorBody()?.byteStream(),
StandardCharsets.UTF_8,
),
) as OperationOutcome

operationOutcome.issue.forEach { operationOutcomeIssueComponent ->
Timber.e(
"SERVER ${operationOutcomeIssueComponent.severity} - HTTP ${resourceSyncException.exception.code()} | Code - ${operationOutcomeIssueComponent.code} | Diagnostics - ${operationOutcomeIssueComponent.diagnostics}",
)
}
} else {
Timber.e(resourceSyncException.exception)
}
}
} catch (e: Exception) {
Expand Down

0 comments on commit 846a085

Please sign in to comment.