in converter/dicom-cast/src/Microsoft.Health.DicomCast.Core/Features/Fhir/FhirTransactionExecutor.cs [82:122]
private static HttpStatusCode ValidateBundleEntryAndGetStatusCode(Bundle.EntryComponent entry, int entryIndex)
{
if (entry == null)
{
throw new InvalidFhirResponseException(
string.Format(CultureInfo.InvariantCulture, DicomCastCoreResource.MissingBundleEntry, entryIndex));
}
if (entry.Response == null)
{
throw new InvalidFhirResponseException(
string.Format(CultureInfo.InvariantCulture, DicomCastCoreResource.MissingBundleEntryResponse, entryIndex));
}
if (entry.Response.Status == null)
{
throw new InvalidFhirResponseException(
string.Format(CultureInfo.InvariantCulture, DicomCastCoreResource.MissingBundleEntryResponseStatus, entryIndex));
}
ReadOnlySpan<char> statusSpan = entry.Response.Status.AsSpan();
// Based on the spec (http://hl7.org/fhir/R4/bundle-definitions.html#Bundle.entry.response.status),
// the status should be starting with 3 digit HTTP code and may contain the HTTP description associated
// with the status code.
if (statusSpan.Length < 3 ||
(statusSpan.Length > 3 && statusSpan[3] != ' ') ||
!Enum.TryParse(statusSpan.Slice(0, 3).ToString(), out HttpStatusCode parsedStatusCode))
{
throw new InvalidFhirResponseException(
string.Format(CultureInfo.InvariantCulture, DicomCastCoreResource.InvalidBundleEntryResponseStatus, entry.Response.Status, entryIndex));
}
if ((int)parsedStatusCode < 200 || (int)parsedStatusCode >= 300)
{
throw new InvalidFhirResponseException(
string.Format(CultureInfo.InvariantCulture, DicomCastCoreResource.MismatchTransactionStatusCode, entry.Response.Status, entryIndex));
}
return parsedStatusCode;
}