FirelyTeam / firely-net-sdk

The official Firely .NET SDK for HL7 FHIR
Other
830 stars 345 forks source link

HttpResponse result does not correctly indicate unexpected body type for Bundle #2772

Closed radupurdea closed 6 months ago

radupurdea commented 7 months ago

When doing a Http request, if the bundle returns an unexpected body type, the error message is incorrect.

Please see lines 909 and 912 of BaseFhirClient. https://github.com/FirelyTeam/firely-net-sdk/blob/dc32002c616baac8e7518eb587aae210f1d345ba/src/Hl7.Fhir.Base/Rest/BaseFhirClient.cs#L909

To Reproduce Steps to reproduce the behavior: This could be reproduced in unit tests by returning a different resource type than requested.

  1. Execute a search request that should return a bundle, for example on the Practitioner endpoint.
  2. Mock the IFhirSerializationEngine and have it return a resource type of ImagingStudy (for example)
  3. The above code will throw: FhirOperationException : Operation GET on <URL HERE> expected a body of type Bundle but a Bundle was returned.

Expected behavior The message in the exception should indicate the unexpected resource type: The above code will throw: FhirOperationException : Operation GET on <URL HERE> expected a body of type Practitioner but a ImagingStudy was returned.

Note: I am assuming the message here was to indicate the types of resources within the bundle entries...

Version used:

ewoutkramer commented 7 months ago

Ha, this is not going to be very informative indeed: $"expected a body of type {typeof(TResource).Name} but a {typeof(TResource).Name} was returned.";, that's twice typeof(TResource).Name. Thanks for spotting it!

ewoutkramer commented 7 months ago

It will become "Operation GET......expected a body type of Bundle, but a ImagingStudy was returned". We don't really interpret the search string to figure out what kind of search results should be in the Bundle. And by the way, because of the _include feature, the Bundle could contain other types of resources than the one you are searching for !