private static async Task <ITypedElement> parseResourceAsync(string bodyText, string contentType, IStructureDefinitionSummaryProvider provider, bool throwOnFormatException) { if (bodyText == null) { throw Error.ArgumentNull(nameof(bodyText)); } if (provider == null) { throw Error.ArgumentNull(nameof(provider)); } var fhirType = ContentType.GetResourceFormatFromContentType(contentType); if (fhirType == ResourceFormat.Unknown) { throw new UnsupportedBodyTypeException( "Endpoint returned a body with contentType '{0}', while a valid FHIR xml/json body type was expected. Is this a FHIR endpoint?" .FormatWith(contentType), contentType, bodyText); } if (!SerializationUtil.ProbeIsJson(bodyText) && !SerializationUtil.ProbeIsXml(bodyText)) { throw new UnsupportedBodyTypeException( "Endpoint said it returned '{0}', but the body is not recognized as either xml or json.".FormatWith(contentType), contentType, bodyText); } try { return((fhirType == ResourceFormat.Json) ? (await FhirJsonNode.ParseAsync(bodyText).ConfigureAwait(false)).ToTypedElement(provider) : (await FhirXmlNode.ParseAsync(bodyText).ConfigureAwait(false)).ToTypedElement(provider)); } catch (FormatException) when(!throwOnFormatException) { return(null); } }