diff --git a/engine/src/main/java/com/google/android/fhir/sync/FhirSyncWorker.kt b/engine/src/main/java/com/google/android/fhir/sync/FhirSyncWorker.kt index 3139f699d6..bbafa70d6a 100644 --- a/engine/src/main/java/com/google/android/fhir/sync/FhirSyncWorker.kt +++ b/engine/src/main/java/com/google/android/fhir/sync/FhirSyncWorker.kt @@ -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) {