Stream: dotnet
Topic: ExceptionHandling - OperationOutcome is null at client side
Harald Sømnes Hanssen (Sep 12 2016 at 12:59):
We're using the Hl7.DSTU2.Core version 0.90.6.26409
When an exception response is sent from the server, we are currently experiencing that the client gets an OperationOutcome which is null. We can see in fiddler that there is an OperationOutcome object sent with the exception, so it must be on the client side. Is there a setting or something we should be aware of?
Currently we're only using the DSTU2 client for integrationtests, however, the tests will be used by third parties as examples of how to communicate with our implementation of a given service with the client.
Query which will fail:
[Test] public void ThisTest_WillHaveAnException() { var url = "http://fhirtest.uhn.ca/baseDstu2/"; var uri = new Uri(url); var _client = new FhirClient(uri); var searchParams = new SearchParams(); searchParams.Add("bogus", "dude"); var result = Assert.Throws<FhirOperationException>(() => _client.Search<CommunicationRequest>(searchParams)); Assert.IsTrue(result.Outcome != null, "Why is this null?"); }
The result will contain an error, however the result.OperationOutcome will be null.
Anyone else experienced this? Are we using the exceptionhandling wrong on the client side?
Brian Postlethwaite (Sep 12 2016 at 22:19):
What you are doing is mostly right.
The return type of the Search is a Bindle, so can't be an OperationOutcome too.
To get the operation outcome from the failed call you need to:
OperationOutcome operationOutcome = client.LastBodyAsResource as OperationOutcome;
Harald Sømnes Hanssen (Sep 13 2016 at 07:09):
Updated the code, but the OperationOutcome is still null when we add your snippet. So something is odd.
[Test] public void ThisTest_WillHaveAnException() { var url = "http://fhirtest.uhn.ca/baseDstu2/"; var uri = new Uri(url); var _client = new FhirClient(uri); var searchParams = new SearchParams(); searchParams.Add("bogus", "dude"); var result = Assert.Throws<FhirOperationException>(() => _client.Search<CommunicationRequest>(searchParams)); var operationOutcome = _client.LastBodyAsResource as OperationOutcome; Assert.IsTrue(operationOutcome != null, "Why is this null?"); var json = JsonConvert.SerializeObject(operationOutcome); Console.WriteLine(json); }
Edit: I think I found the culprit. It is the client. The dstu2 core version we are using due to be compatible with Sparks.Engine, has some bugs which aren't critical on the server side, however, on the client side it is differently. As soon as I updated from alpha-1 to alpha-5, the operationoutcome isn't null anymore.
Brian Postlethwaite (Sep 13 2016 at 07:20):
Yes, there were some issues with the older versions.
That latest prerelease is pretty good.
(and assuming you mean the fhirclient rather than spark.engine)
Harald Sømnes Hanssen (Sep 13 2016 at 08:29):
Yeah, I'm talking about the fhirclient (or HL7.DSTU2.Core)
I'm hoping that the spark.engine will be updated soon since there are a lot of breaking changes with the new core. My project uses spark.engine for some of the functionality. Luckily consumers of the FHIR server endpoint do not have to depend on the alpha-1 release of the core.
Brian Postlethwaite (Sep 13 2016 at 08:33):
Yes, my server needed quite a bit of updating too.
Still haven't pushed an updated version public yet either.
Brian Postlethwaite (Sep 13 2016 at 08:34):
(Though I have pushed my STU3 version today - complete with some Fluentpath new additions)
Last updated: Apr 12 2022 at 19:14 UTC