Skip to content

Return OperationOutcome for FHIRServerError#276

Merged
sameeragunarathne merged 2 commits intowso2:mainfrom
mahimadesilva:fix-generic-error-message
Apr 3, 2026
Merged

Return OperationOutcome for FHIRServerError#276
sameeragunarathne merged 2 commits intowso2:mainfrom
mahimadesilva:fix-generic-error-message

Conversation

@mahimadesilva
Copy link
Copy Markdown
Contributor

@mahimadesilva mahimadesilva commented Mar 27, 2026

Purpose

Resolves https://github.com/wso2-enterprise/open-healthcare/issues/2008.

Summary by CodeRabbit

  • Bug Fixes
    • Improved error handling for resource creation: server-side error details are now surfaced as standard FHIR OperationOutcome responses when possible.
    • HTTP status information from upstream FHIR server errors is preserved and propagated to clients when available, yielding more accurate response statuses.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Mar 27, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 1303a680-4515-4230-b8a0-ec3661a4a81f

📥 Commits

Reviewing files that changed from the base of the PR and between dfb061d and 0b8e76a.

📒 Files selected for processing (2)
  • fhir-service/service.bal
  • fhir-service/source_connect.bal
🚧 Files skipped from review as they are similar to previous changes (1)
  • fhir-service/source_connect.bal

Walkthrough

create in fhir-service/source_connect.bal now accepts an optional r4:FHIRContext? fhirContext and, on FHIRServerError, attempts to extract the server response's resource and clone it to an r4:OperationOutcome, updating fhirContext's status when applicable; call sites in fhir-service/service.bal were updated to pass fhirContext.

Changes

Cohort / File(s) Summary
Connector: create signature & error handling
fhir-service/source_connect.bal
Added optional r4:FHIRContext? fhirContext = () parameter to create. On FHIRServerError, extracts response.detail().'resource, attempts JSON → r4:OperationOutcome clone, may update fhirContext status code, and returns the OperationOutcome; falls back to existing createFHIRError behavior if extraction/clone fails.
Service call sites: propagate FHIRContext
fhir-service/service.bal
Updated all resource creation calls to pass the active fhirContext (e.g., create(..., fhirContext)), adjusting check create(...) usage where applicable. No other handler logic changed.

Sequence Diagram(s)

mermaid
sequenceDiagram
participant Client
participant Service as FHIR Service (service.bal)
participant Connector as FHIR Connector (source_connect.bal)
participant Server as FHIR Server
Client->>Service: POST /[Resource] with payload (has r4:FHIRContext)
Service->>Connector: create(fhirConnector, ResourceType, payload, fhirContext)
Connector->>Server: send create request
alt success (201/2xx)
Server-->>Connector: 201 Created + resource
Connector-->>Service: r4:DomainResource
Service-->>Client: 201 Created + resource
else server error
Server-->>Connector: FHIRServerError (with response.detail().'resource')
Connector->>Connector: extract and try clone to r4:OperationOutcome
alt clone succeeds
Connector->>Connector: update fhirContext status (if r4:FHIRContext)
Connector-->>Service: r4:OperationOutcome
Service-->>Client: OperationOutcome (with status from fhirContext if set)
else clone fails
Connector-->>Service: r4:FHIRError (existing fallback)
Service-->>Client: FHIRError response
end
end

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐇 Soft paws on keys, a connector's tune,
When servers grumble under the moon,
I pull out the detail, shape it right—
An Outcome returned in gentlest light. ✨

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description is incomplete. It only includes a Purpose section with an issue link, but is missing Goals, Approach, User stories, Release note, and other required template sections. Complete the PR description by adding Goals, Approach, Release note, and other applicable sections from the template to provide full context for reviewers.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely summarizes the main change: returning an OperationOutcome for FHIRServerError instead of a generic error.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@fhir-service/source_connect.bal`:
- Around line 25-34: The fallback currently hardcodes http:STATUS_BAD_REQUEST
when handling a fhirClient:FHIRServerError, which hides the upstream status;
inside the fhirClient:FHIRServerError guard (where `response` is the error),
extract the upstream status code (e.g., call `response.statusCode()` or use the
status property on the error), and pass that value into r4:createFHIRError's
httpStatusCode argument instead of http:STATUS_BAD_REQUEST so the original
upstream status (500/422/etc.) is preserved when returning the fallback error.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 8457cf98-63a0-47bc-9a1f-fa1eb9af1f52

📥 Commits

Reviewing files that changed from the base of the PR and between 4172b32 and dfb061d.

📒 Files selected for processing (1)
  • fhir-service/source_connect.bal

@mahimadesilva
Copy link
Copy Markdown
Contributor Author

@coderabbitai incremental review

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Mar 31, 2026

@mahimadesilva Sure! I'll perform an incremental review of the changes in this PR now.

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@mahimadesilva
Copy link
Copy Markdown
Contributor Author

@coderabbitai review

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Mar 31, 2026

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@sameeragunarathne sameeragunarathne merged commit a092024 into wso2:main Apr 3, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants