-
Notifications
You must be signed in to change notification settings - Fork 516
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Return BadRequestException with valid message when input json body is invalid #2239
Return BadRequestException with valid message when input json body is invalid #2239
Conversation
/azp run |
Azure Pipelines successfully started running 1 pipeline(s). |
When submitting a Coverage resource I'm getting some unexpected results.
But for this resource I'm getting back the expected failure with a message that the status can't be null.
|
…te-search-expression-resulting-in-500
…te-search-expression-resulting-in-500
…te-search-expression-resulting-in-500
…te-search-expression-resulting-in-500
…r value is null instead of 500
…xpression-resulting-in-500' of https://github.com/microsoft/fhir-server into personal/apurvabhale/member-match-query-create-search-expression-resulting-in-500
...icrosoft.Health.Fhir.Shared.Core.UnitTests/Features/Search/TypedElementSearchIndexerTests.cs
Outdated
Show resolved
Hide resolved
|
||
namespace Microsoft.Health.Fhir.Core.UnitTests.Features.Search | ||
{ | ||
public class TypedElementSearchIndexerTests |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a lot of work put into getting the search indexer out of "Shared" and into FHIR agnostic core, a little sad to see it back :(
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
:( I can see if I can move this test to Microsoft.Health.Fhir.Core.UnitTests from Microsoft.Health.Fhir.Shared.Core.UnitTests
if (searchParameter is null) | ||
{ | ||
throw new BadRequestException(string.Format(Resources.ValueCannotBeNull, "Search Parameter")); | ||
} | ||
|
||
if (value is null) | ||
{ | ||
throw new BadRequestException(string.Format(Resources.ValueCannotBeNull, searchParameter.Expression)); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should the search indexer handle this instead? This still looks like an ArgumentException in this class.
foreach (ISearchValue searchValue in ExtractSearchValues(
searchParameter.Url.ToString(),
searchParameter.Type,
searchParameter.TargetResourceTypes,
resource,
searchParameter.Expression,
context))
{
if(searchValue != null) {
yield return new SearchIndexEntry(searchParameterInfo, searchValue);
}
}
or
foreach (ISearchValue searchValue in ExtractSearchValues(
searchParameter.Url.ToString(),
searchParameter.Type,
searchParameter.TargetResourceTypes,
resource,
searchParameter.Expression,
context))
{
try {
yield return new SearchIndexEntry(searchParameterInfo, searchValue);
} catch(ArgumentException) { throw new BadRequestException(...) }
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added the null check in TypedElementSearchIndexer.ProcessNonCompositeSearchParameter. I noticed there is another function ProcessCompositeSearchParameter which calls the SearchIndexEntry too. Wondering if the null check would also apply to the composite Search parameter. Any thoughts?
...icrosoft.Health.Fhir.Shared.Core.UnitTests/Features/Search/TypedElementSearchIndexerTests.cs
Outdated
Show resolved
Hide resolved
…member-match-query-create-search-expression-resulting-in-500
Possibly related to AB#86850 |
Description
For invalid json body requests Fhir server returns 500. If the input json is not in the correct format then we are parsing the body at FhirJsonInputFormatter and passing the initial validations for required fields at ModelAttributeValidator.
e.g.
If the body contains Coverage.status = "", then after parsing Coverage.status = null & Coverage.statusElement = null, resulting into minimum cardinality error as expected.
If the body contains Coverage.status = , then after parsing Coverage.status = null & Coverage.statusElement = {value=null}, which passes the Firely validation and CodeToTokenSearchValueConverter returns null causing search index entry to fail.
In this PR we are returning BadRequestException with a valid message instead of 500
Related issues
Addresses 85266
Testing
FHIR Team Checklist
Semver Change (docs)
Patch|Skip|Feature|Breaking (reason)