Skip to content

Commit 846a085

Browse files
committed
Catch and log non-HAPI FHIR Exceptions
1 parent 59b4ff4 commit 846a085

File tree

1 file changed

+16
-15
lines changed

1 file changed

+16
-15
lines changed

engine/src/main/java/com/google/android/fhir/sync/FhirSyncWorker.kt

+16-15
Original file line numberDiff line numberDiff line change
@@ -164,21 +164,22 @@ abstract class FhirSyncWorker(appContext: Context, workerParams: WorkerParameter
164164

165165
try {
166166
exceptions.forEach { resourceSyncException ->
167-
val operationOutcome =
168-
jsonParser.parseResource(
169-
IOUtils.toString(
170-
(resourceSyncException.exception as HttpException)
171-
.response()
172-
?.errorBody()
173-
?.byteStream(),
174-
StandardCharsets.UTF_8,
175-
),
176-
) as OperationOutcome
177-
178-
operationOutcome.issue.forEach { operationOutcomeIssueComponent ->
179-
Timber.e(
180-
"SERVER ${operationOutcomeIssueComponent.severity} - HTTP ${resourceSyncException.exception.code()} | Code - ${operationOutcomeIssueComponent.code} | Diagnostics - ${operationOutcomeIssueComponent.diagnostics}",
181-
)
167+
if (resourceSyncException.exception is HttpException) {
168+
val operationOutcome =
169+
jsonParser.parseResource(
170+
IOUtils.toString(
171+
resourceSyncException.exception.response()?.errorBody()?.byteStream(),
172+
StandardCharsets.UTF_8,
173+
),
174+
) as OperationOutcome
175+
176+
operationOutcome.issue.forEach { operationOutcomeIssueComponent ->
177+
Timber.e(
178+
"SERVER ${operationOutcomeIssueComponent.severity} - HTTP ${resourceSyncException.exception.code()} | Code - ${operationOutcomeIssueComponent.code} | Diagnostics - ${operationOutcomeIssueComponent.diagnostics}",
179+
)
180+
}
181+
} else {
182+
Timber.e(resourceSyncException.exception)
182183
}
183184
}
184185
} catch (e: Exception) {

0 commit comments

Comments
 (0)