Fix incorrect 500 status on bundle POST with only Patients#156
Open
mherman22 wants to merge 1 commit into
Open
Fix incorrect 500 status on bundle POST with only Patients#156mherman22 wants to merge 1 commit into
mherman22 wants to merge 1 commit into
Conversation
When a bundle contains only Patient resources (no other resource types),
otherResources.entry is empty and the callback returns {} with no code.
The status code comparison (patients.code > otherResources.code) becomes
(200 > undefined) which is false in JS, so code falls through to
otherResources.code (undefined) and then defaults to 500.
Fix by returning code: 200 from both empty-path callbacks. Also return
a valid responseBundle/responseHeaders/operationSummary from the empty
patients path to prevent a crash on results.patients.responseBundle.entry
when a bundle has only non-Patient resources.
Fixes intrahealth#68
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.
Problem
When a FHIR transaction bundle containing only Patient resources is POSTed to
/, the server returns HTTP 500 instead of 200.Root cause in
fhir.jsline 204:Then at line 240:
200 > undefinedisfalsein JavaScript, socodegetsundefined, then defaults to 500.The symmetric case also has a bug: if the bundle has only non-Patient resources,
results.patientsis{}, and line 249 (results.patients.responseBundle.entry) crashes withCannot read properties of undefined.Fix
Return
{code: 200}from the empty otherResources callback, and{code: 200, responseBundle: {entry: []}, responseHeaders: {}, operationSummary: []}from the empty patients callback.Fixes #68