Fixing incorrect 500 error on get export job status. - #5768
Fixing incorrect 500 error on get export job status.#5768v-isyamauchi-gh wants to merge 3 commits into
Conversation
There was a problem hiding this comment.
Pull request overview
This PR fixes an export failure mode where creating an $export job with an invalid _type later surfaced as a 500 Internal Server Error. It adds explicit resource-type validation in the export orchestrator so invalid types fail the job as a 400 Bad Request, and it adds unit/E2E coverage for the scenario.
Changes:
- Add
ISearchService.IsValidResourceType(...)and implement it for SQL Server and Cosmos search services. - Validate export job
_typevalues in both SQL and Cosmos export orchestrator jobs before enqueuing/processing child work. - Add unit tests for the orchestrator validation and an E2E test that asserts the status endpoint returns
400for invalid_type.
Reviewed changes
Copilot reviewed 11 out of 11 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| test/Microsoft.Health.Fhir.Shared.Tests.Integration/Persistence/CosmosDbFhirStorageTestsFixture.cs | Updates test fixture construction to match the updated Cosmos search service constructor. |
| test/Microsoft.Health.Fhir.Shared.Tests.E2E/Rest/Export/ExportTests.cs | Adds E2E test for invalid _type resulting in 400 BadRequest on status polling. |
| src/Microsoft.Health.Fhir.SqlServer/Features/Search/SqlServerSearchService.cs | Implements IsValidResourceType using the SQL model’s resource type map. |
| src/Microsoft.Health.Fhir.SqlServer/Features/Operations/Export/SqlExportOrchestratorJob.cs | Adds resource type validation step before export orchestration continues. |
| src/Microsoft.Health.Fhir.Shared.Core.UnitTests/Microsoft.Health.Fhir.Shared.Core.UnitTests.projitems | Includes the new unit test file in the shared unit test project items. |
| src/Microsoft.Health.Fhir.Shared.Core.UnitTests/Features/Operations/Export/ExportOrchestratorJobTests.cs | Adds unit tests for the orchestrator’s resource type validation behavior. |
| src/Microsoft.Health.Fhir.CosmosDb/Features/Search/FhirCosmosSearchService.cs | Adds IModelInfoProvider dependency and implements IsValidResourceType for Cosmos. |
| src/Microsoft.Health.Fhir.CosmosDb/Features/Operations/Export/CosmosExportOrchestratorJob.cs | Adds resource type validation step for Cosmos export orchestration. |
| src/Microsoft.Health.Fhir.Core/Features/Search/SearchService.cs | Adds base implementation stub for IsValidResourceType on the abstract search service base. |
| src/Microsoft.Health.Fhir.Core/Features/Search/ISearchService.cs | Adds the IsValidResourceType contract to the search service interface. |
| src/Microsoft.Health.Fhir.Core/Features/Operations/Export/ExportOrchestratorJob.cs | Introduces shared ValidateResourceTypes(...) helper used by orchestrators to fail invalid jobs with 400. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 13 out of 13 changed files in this pull request and generated 1 comment.
Suppressed comments (1)
src/Microsoft.Health.Fhir.Core/Features/Operations/Export/ExportOrchestratorJob.cs:103
JobExecutionExceptiontakes anisCustomerCausedflag; invalid_typevalues are user input errors, so this should be marked customer-caused. Keeping this asfalsecan skew telemetry/alerts by treating a 400 as an internal failure.
var message = $"Invalid resource type(s): {string.Join(", ", invalidTypes)}";
record.FailureDetails = new JobFailureDetails(message, HttpStatusCode.BadRequest);
throw new JobExecutionException(message, record, false);
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #5768 +/- ##
==========================================
+ Coverage 78.79% 78.81% +0.01%
==========================================
Files 1020 1020
Lines 37783 37801 +18
Branches 5754 5758 +4
==========================================
+ Hits 29772 29792 +20
+ Misses 6594 6592 -2
Partials 1417 1417 🚀 New features to boost your workflow:
|
Description
Return 400 instead of 500 for export jobs with invalid resource types
When an $export job is created with an invalid _type parameter, the orchestrator now validates resource types before enqueuing child jobs. Invalid types cause the job to fail with 400 Bad Request instead of an unhandled ResourceNotFoundException that surfaced as 500 Internal Server Error.
Related issues
Addresses [issue #204452].
Bug 204452: Export Job returns 500 when customer enters invalid type.
Testing
Tested by adding UTs and E2E tests.
FHIR Team Checklist
Semver Change (docs)
Patch|Skip|Feature|Breaking (reason)