Skip to content

Fixes the $expand to return 404 when ValueSet not found#5580

Open
rbans96 wants to merge 7 commits into
mainfrom
personal/ribans/expand-log-level-fix
Open

Fixes the $expand to return 404 when ValueSet not found#5580
rbans96 wants to merge 7 commits into
mainfrom
personal/ribans/expand-log-level-fix

Conversation

@rbans96
Copy link
Copy Markdown
Contributor

@rbans96 rbans96 commented May 20, 2026

Description

FirelyTerminologyServiceProxy.ExpandAsync() logs all exceptions at LogError, including benign "valueset is unknown" scenarios where HTTP 200 is still returned. This triggers FHIR002 monitor and creates unnecessary ICMs.
Also returns 404 status code instead of 200

The FHIR spec (ValueSet $expand) requires an error OperationOutcome with a non-2xx status but does not mandate a specific code. Since Firely surfaces this as HttpStatusCode.NotFound, 404 is the most semantically consistent choice. The existing OperationOutcomeExceptionFilterAttribute already maps ResourceNotFoundException → 404.

Fix: Catch FhirOperationException with "is unknown" separately and log at Warning instead of Error. Added unit tests for both paths.

Return 404 if valueset not found

Related issues

Addresses - https://microsofthealth.visualstudio.com/Health/_workitems/edit/192757

Testing

Added unit tests

FHIR Team Checklist

  • Update the title of the PR to be succinct and less than 65 characters
  • Add a milestone to the PR for the sprint that it is merged (i.e. add S47)
  • Tag the PR with the type of update: Bug, Build, Dependencies, Enhancement, New-Feature or Documentation
  • Tag the PR with Open source, Azure API for FHIR (CosmosDB or common code) or Azure Healthcare APIs (SQL or common code) to specify where this change is intended to be released.
  • Tag the PR with Schema Version backward compatible or Schema Version backward incompatible or Schema Version unchanged if this adds or updates Sql script which is/is not backward compatible with the code.
  • When changing or adding behavior, if your code modifies the system design or changes design assumptions, please create and include an ADR.
  • CI is green before merge Build Status
  • Review squash-merge requirements

Semver Change (docs)

Patch|Skip|Feature|Breaking (reason)

@rbans96 rbans96 added this to the CY25Q3/2Wk07 milestone May 20, 2026
@rbans96 rbans96 requested a review from a team as a code owner May 20, 2026 19:13
@rbans96 rbans96 added Bug Bug bug bug. Azure Healthcare APIs Label denotes that the issue or PR is relevant to the FHIR service in the Azure Healthcare APIs No-PaaS-breaking-change No-ADR ADR not needed labels May 20, 2026
…e may be null'

Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
@codecov-commenter
Copy link
Copy Markdown

codecov-commenter commented May 20, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 77.37%. Comparing base (89fb48b) to head (8480bda).

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #5580      +/-   ##
==========================================
+ Coverage   77.27%   77.37%   +0.09%     
==========================================
  Files         997      997              
  Lines       36559    36564       +5     
  Branches     5549     5549              
==========================================
+ Hits        28251    28291      +40     
+ Misses       6935     6898      -37     
- Partials     1373     1375       +2     

see 11 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

rbans96 added 3 commits May 28, 2026 09:37
Throw ResourceNotFoundException instead of returning OperationOutcome
when Firely surfaces an unknown ValueSet (HttpStatusCode.NotFound).
The existing OperationOutcomeExceptionFilter maps it to 404.

Added catch (ResourceNotFoundException) { throw; } in the handler to
prevent double Error-level logging. Only Warning is now logged.

FHIR spec only requires error OperationOutcome with non-2xx status;
404 is consistent with Firely NotFound semantics.
@rbans96 rbans96 changed the title Downgrade unknown ValueSet expand failures to LogWarning Fixes the $expand operation to return HTTP 404when a ValueSet not found Jun 2, 2026
@rbans96 rbans96 changed the title Fixes the $expand operation to return HTTP 404when a ValueSet not found Fixes the $expand to return 404 when ValueSet not found Jun 2, 2026
feordin
feordin previously approved these changes Jun 2, 2026
abiisnn
abiisnn previously approved these changes Jun 3, 2026
Copy link
Copy Markdown
Contributor

@abiisnn abiisnn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Locally tested!

Before:

Image

After:

Image

@rbans96 rbans96 dismissed stale reviews from abiisnn and feordin via 95b8d37 June 3, 2026 19:23
…d-log-level-fix

# Conflicts:
#	.github/copilot-instructions.md
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Azure Healthcare APIs Label denotes that the issue or PR is relevant to the FHIR service in the Azure Healthcare APIs Bug Bug bug bug. No-ADR ADR not needed No-PaaS-breaking-change

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants