From b83856bb1c5fd816f78aa5e28733889bf5a66072 Mon Sep 17 00:00:00 2001 From: mmsmits Date: Wed, 3 Jan 2024 13:50:48 +0100 Subject: [PATCH 1/2] fix: do not catch FhirOperationExceptions in LocalTerminologyService --- .../Specification/Terminology/LocalTerminologyService.cs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/Hl7.Fhir.Shims.Base/Specification/Terminology/LocalTerminologyService.cs b/src/Hl7.Fhir.Shims.Base/Specification/Terminology/LocalTerminologyService.cs index 1c177bb453..f795403cb2 100644 --- a/src/Hl7.Fhir.Shims.Base/Specification/Terminology/LocalTerminologyService.cs +++ b/src/Hl7.Fhir.Shims.Base/Specification/Terminology/LocalTerminologyService.cs @@ -132,7 +132,6 @@ private async Task getExpandedValueSet(ValueSet vs, string operation) } } catch (TerminologyServiceException e) -#pragma warning restore CS0618 { // Unprocessable entity throw new FhirOperationException( @@ -176,7 +175,7 @@ public async T.Task ValueSetValidateCode(Parameters parameters, stri else return await validateCodeVS(valueSet, validateCodeParams.Code?.Value, validateCodeParams.System?.Value, validateCodeParams.Display?.Value, validateCodeParams.Abstract?.Value).ConfigureAwait(false); } - catch (Exception e) + catch (Exception e) when (e is not FhirOperationException) { //500 internal server error throw new FhirOperationException(e.Message, (HttpStatusCode)500); From b3a89903fe2475dcd9ed067317a3e6d3d248c5e7 Mon Sep 17 00:00:00 2001 From: mmsmits Date: Wed, 3 Jan 2024 14:05:10 +0100 Subject: [PATCH 2/2] expanded unit tests to check for correct status code --- .../Source/TerminologyTests.cs | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/Hl7.Fhir.Specification.Shared.Tests/Source/TerminologyTests.cs b/src/Hl7.Fhir.Specification.Shared.Tests/Source/TerminologyTests.cs index 2f98a04510..4332980deb 100644 --- a/src/Hl7.Fhir.Specification.Shared.Tests/Source/TerminologyTests.cs +++ b/src/Hl7.Fhir.Specification.Shared.Tests/Source/TerminologyTests.cs @@ -312,8 +312,8 @@ public async void LocalTermServiceValidateCodeWithParamsTest() inParams = new ValidateCodeParameters() .WithValueSet(url: "http://hl7.org/fhir/ValueSet/substance-code") .WithCode(code: "1166006", system: "http://snomed.info/sct"); - await Assert.ThrowsAsync(async () => await svc.ValueSetValidateCode(inParams)); - + var exception = await Assert.ThrowsAsync(async () => await svc.ValueSetValidateCode(inParams)); + Assert.Equal(System.Net.HttpStatusCode.UnprocessableEntity, exception.Status); } [Fact] @@ -332,8 +332,8 @@ public async T.Task LocalTermServiceValidateCodeWithoutSystemOrContext() } }; - await Assert.ThrowsAsync(async () => await svc.ValueSetValidateCode(inParams)); - + var exception = await Assert.ThrowsAsync(async () => await svc.ValueSetValidateCode(inParams)); + Assert.Equal(System.Net.HttpStatusCode.UnprocessableEntity, exception.Status); } @@ -363,7 +363,8 @@ public async T.Task LocalTermServiceUsingDuplicateParameters() } }; - await Assert.ThrowsAsync(async () => await svc.ValueSetValidateCode(inParams)); + var exception = await Assert.ThrowsAsync(async () => await svc.ValueSetValidateCode(inParams)); + Assert.Equal(System.Net.HttpStatusCode.UnprocessableEntity, exception.Status); } [Fact]