From 8a3d7d36709ac33a59d5ad5f2bd44ed2380866f6 Mon Sep 17 00:00:00 2001 From: dotasek Date: Wed, 22 Jun 2022 13:43:28 -0400 Subject: [PATCH] Catch ClassCastException and report clearer error message --- .../org/hl7/fhir/r5/utils/client/FHIRToolingClient.java | 7 +++++-- .../hl7/fhir/r5/utils/client/FHIRToolingClientTest.java | 6 ++---- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/utils/client/FHIRToolingClient.java b/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/utils/client/FHIRToolingClient.java index d052f681a..268f3c814 100644 --- a/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/utils/client/FHIRToolingClient.java +++ b/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/utils/client/FHIRToolingClient.java @@ -171,10 +171,13 @@ public class FHIRToolingClient { public TerminologyCapabilities getTerminologyCapabilities() { TerminologyCapabilities capabilities = null; - capabilities = getCapabilities(resourceAddress.resolveMetadataTxCaps(), + try { + capabilities = getCapabilities(resourceAddress.resolveMetadataTxCaps(), "TerminologyCapabilities", "Error fetching the server's terminology capabilities"); - + } catch (ClassCastException e) { + throw new FHIRException("Unexpected response format for Terminology Capability metadata", e); + } return capabilities; } diff --git a/org.hl7.fhir.r5/src/test/java/org/hl7/fhir/r5/utils/client/FHIRToolingClientTest.java b/org.hl7.fhir.r5/src/test/java/org/hl7/fhir/r5/utils/client/FHIRToolingClientTest.java index bd5d90026..c617aee8e 100644 --- a/org.hl7.fhir.r5/src/test/java/org/hl7/fhir/r5/utils/client/FHIRToolingClientTest.java +++ b/org.hl7.fhir.r5/src/test/java/org/hl7/fhir/r5/utils/client/FHIRToolingClientTest.java @@ -32,8 +32,7 @@ import okhttp3.Headers; import okhttp3.Request; import okhttp3.internal.http2.Header; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.*; import static org.mockito.Mockito.times; class FHIRToolingClientTest { @@ -171,10 +170,9 @@ class FHIRToolingClientTest { ArgumentCaptor headersArgumentCaptor = ArgumentCaptor.forClass(Headers.class); toolingClient.setClientHeaders(getHeaders()); Exception exception = assertThrows(FHIRException.class, () -> { - toolingClient.getTerminologyCapabilities(); - }); + assertEquals(exception.getCause().getClass(), ClassCastException.class); } @Test