Better handling of errors returned from tx.fhir.org

This commit is contained in:
Grahame Grieve 2023-09-20 11:09:33 +10:00
parent 8bae1a23ff
commit a21b28bf3a
3 changed files with 21 additions and 7 deletions

View File

@ -88,9 +88,11 @@ public class TerminologyClientR4 implements ITerminologyClient {
vs2 = client.expandValueset(vs2, p2, params); // todo: second parameter
return (ValueSet) VersionConvertorFactory_40_50.convertResource(vs2);
} catch (org.hl7.fhir.r4.utils.client.EFhirClientException e) {
throw new org.hl7.fhir.r5.utils.client.EFhirClientException(e.getMessage(),
(org.hl7.fhir.r5.model.OperationOutcome) VersionConvertorFactory_40_50.convertResource(e.getServerErrors().get(0)));
if (e.getServerErrors().size() > 0) {
throw new org.hl7.fhir.r5.utils.client.EFhirClientException(e.getMessage(), (org.hl7.fhir.r5.model.OperationOutcome) VersionConvertorFactory_40_50.convertResource(e.getServerErrors().get(0)));
} else {
throw new org.hl7.fhir.r5.utils.client.EFhirClientException(e.getMessage());
}
}
}
@ -165,7 +167,8 @@ public class TerminologyClientR4 implements ITerminologyClient {
@Override
public Bundle validateBatch(Bundle batch) {
return (Bundle) VersionConvertorFactory_40_50.convertResource(client.transaction((org.hl7.fhir.r4.model.Bundle) VersionConvertorFactory_40_50.convertResource(batch)));
org.hl7.fhir.r4.model.Bundle result = client.transaction((org.hl7.fhir.r4.model.Bundle) VersionConvertorFactory_40_50.convertResource(batch));
return result == null ? null : (Bundle) VersionConvertorFactory_40_50.convertResource(result);
}
@Override

View File

@ -449,8 +449,14 @@ public class FHIRToolingClient {
throw new EFhirClientException("Server returned error code " + result.getHttpStatus(),
(OperationOutcome) result.getPayload());
}
} catch (IOException e) {
throw new FHIRException(e);
} catch (EFhirClientException e) {
if (e.getServerErrors().size() > 0) {
throw new EFhirClientException(e.getMessage(), e.getServerErrors().get(0));
} else {
throw new EFhirClientException(e.getMessage(), e);
}
} catch (Exception e) {
throw new EFhirClientException(e.getMessage(), e);
}
return result == null ? null : (ValueSet) result.getPayload();
}

View File

@ -273,7 +273,12 @@ public class FhirRequestBuilder {
}
if (error != null) {
throw new EFhirClientException("Error from server: " + ResourceUtilities.getErrorDescription(error), error);
String s = ResourceUtilities.getErrorDescription(error);
System.out.println(s);
if (s.startsWith("Unable to find value set")) {
System.out.println("!");
}
throw new EFhirClientException("Error from "+source+": " + ResourceUtilities.getErrorDescription(error), error);
}
return resource;