I am using Hl7.Fhir.Rest.FhirClient to update some resources on our local fhir server. However, sometimes we receive the following exception that I cannot identify why it happens? Does anyone have a way to debug the issue to see what is going on

Endpoint returned a body with contentType 'text/html', while a valid FHIR xml/json body type was expected. Is this a FHIR endpoint?

This is also part of the stack trace that we receive

 Hl7.Fhir.Rest.HttpToEntryExtensions.parseResource(String bodyText, String contentType) in C:\src\FHIR\fhir-net-api-DSTU2 - Merge\src\Hl7.Fhir.Core\Rest\HttpToEntryExtensions.cs:139
   Hl7.Fhir.Rest.HttpToEntryExtensions.ToBundleEntry(HttpWebResponse response, Byte[] body) in C:\src\FHIR\fhir-net-api-DSTU2 - Merge\src\Hl7.Fhir.Core\Rest\HttpToEntryExtensions.cs:73
   Hl7.Fhir.Rest.Requester.doRequest(EntryComponent interaction) in C:\src\FHIR\fhir-net-api-DSTU2 - Merge\src\Hl7.Fhir.Core\Rest\Requester.cs:119
   Hl7.Fhir.Rest.Requester.Execute(EntryComponent interaction) in C:\src\FHIR\fhir-net-api-DSTU2 - Merge\src\Hl7.Fhir.Core\Rest\Requester.cs:58
   Hl7.Fhir.Rest.FhirClient.execute(Bundle tx, IEnumerable`1 expect) in C:\src\FHIR\fhir-net-api-DSTU2 - Merge\src\Hl7.Fhir.Core\Rest\FhirClient.cs:807
   Hl7.Fhir.Rest.FhirClient.internalUpdate(TResource resource, Bundle tx) in C:\src\FHIR\fhir-net-api-DSTU2 - Merge\src\Hl7.Fhir.Core\Rest\FhirClient.cs:283
   Hl7.Fhir.Rest.FhirClient.Update(TResource resource, Boolean versionAware) in C:\src\FHIR\fhir-net-api-DSTU2 - Merge\src\Hl7.Fhir.Core\Rest\FhirClient.cs:248
2

There are 2 answers

3
Lloyd McKenzie On

Is the Accept header being set? You should be able to check what's actually being sent by using a tool like Fiddler

0
Raoof On

The cause for the exception would be either the request doesn't reach to the end point due to any security layer in the middle like OAuth or the endpoint, you are trying on, doesn't exist at the service.