Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
radupurdea opened this issue Apr 12, 2024 · 2 comments · Fixed by #2788
Closed

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

radupurdea opened this issue Apr 12, 2024 · 2 comments · Fixed by #2788

Comments

@radupurdea
Copy link

radupurdea commented Apr 12, 2024

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.

static string unexpectedBodyTypeForBundle(Bundle.RequestComponent rc) => $"Operation {rc.Method} on {rc.Url} " +

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:

  • FHIR Version: R4
  • Version: 5.7.0
@ewoutkramer
Copy link
Member

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
Copy link
Member

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
!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants