Return 404 instead of 500 for unknown resource type for Sql#5513
Merged
mikaelweave merged 2 commits intomainfrom Apr 29, 2026
Merged
Return 404 instead of 500 for unknown resource type for Sql#5513mikaelweave merged 2 commits intomainfrom
mikaelweave merged 2 commits intomainfrom
Conversation
…e types Bug: DELETE requests with unknown or case-mismatched resource types threw KeyNotFoundException from GetResourceTypeId() via direct dictionary access. The exception filter had no handler for KeyNotFoundException, resulting in HTTP 500 instead of 404. Fix: Change GetResourceTypeId() to use TryGetValue and throw ResourceNotFoundException (already mapped to 404 by the exception filter) instead of letting KeyNotFoundException bubble up as 500. Dictionary comparers remain StringComparer.Ordinal — the FHIR spec requires case-sensitive resource type matching, so 'patient' correctly returns 404. AB#190027
763cb3c to
51f3a2b
Compare
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #5513 +/- ##
=======================================
Coverage ? 77.61%
=======================================
Files ? 983
Lines ? 37746
Branches ? 6050
=======================================
Hits ? 29296
Misses ? 7081
Partials ? 1369 🚀 New features to boost your workflow:
|
0818472 to
51f3a2b
Compare
feordin
approved these changes
Apr 29, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
SqlServerFhirModel.GetResourceTypeId()performed a case-sensitive dictionary lookup and letKeyNotFoundExceptionbubble up, producing 500 Internal Server Error for any unknown ormis-cased resource type that reached the SQL data layer (for example, a case-mismatched
DELETE /patient/{id}that slipped past routing).Per FHIR, an unknown resource type should produce 404 Not Found, not 500.
Reproduction
DELETE https://localhost:44348/patient/123?hardDelete=true(lowercase).Fix
Changed
GetResourceTypeId()to useTryGetValue()and throwResourceNotFoundException(already mapped to 404 by the exception filter) instead of letting
KeyNotFoundExceptionsurface as 500.
Dictionary comparers for resource type lookups remain
StringComparer.Ordinal— the FHIRspec requires case-sensitive resource type matching.
Now this request will return the below as 404 vs a 500
{ "resourceType": "OperationOutcome", "id": "f84d47cb-357b-43f8-9efb-941fd7f512f8", "meta": { "lastUpdated": "2026-04-29T21:07:03.188648+00:00" }, "issue": [ { "severity": "error", "code": "not-found", "diagnostics": "Resource type 'patient' is not a known resource type." } ] }Impact
the SQL data layer.
GetResourceTypeId()now get a clean 404 instead of an unhandled 500.Related Work Items
AB#190027
Testing
GetResourceTypeId()path.Risks and Follow-ups