Skip to content

[Bundles] Ensure client errors are HTTP400#5589

Open
fhibf wants to merge 8 commits into
mainfrom
user/fernfe/handleClientErrorStatusCode
Open

[Bundles] Ensure client errors are HTTP400#5589
fhibf wants to merge 8 commits into
mainfrom
user/fernfe/handleClientErrorStatusCode

Conversation

@fhibf
Copy link
Copy Markdown
Contributor

@fhibf fhibf commented May 27, 2026

Description

In Parallel Bundles we are now identifying that one of the operations failed with a HTTP400, and the remaining ones are cancelled and marked with HTTP424 (FailedDependency) in logs.

There are now more tests to ensure that HTTP400 is properly returned in those cases.

These changes will also avoid marking bundles as "Failed by client Error" and "Cancelled by Client timeout".

Related issues

Addresses AB#192974.

Testing

Tested locally and through Unit and E2E tests.

FHIR Team Checklist

Semver Change (docs)

Patch|Skip|Feature|Breaking (reason)

@fhibf fhibf requested a review from a team as a code owner May 27, 2026 16:31
@codecov-commenter
Copy link
Copy Markdown

codecov-commenter commented May 27, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 77.37%. Comparing base (ee554e9) to head (882d782).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #5589      +/-   ##
==========================================
+ Coverage   77.33%   77.37%   +0.03%     
==========================================
  Files         996      996              
  Lines       36534    36585      +51     
  Branches     5538     5547       +9     
==========================================
+ Hits        28255    28309      +54     
+ Misses       6912     6903       -9     
- Partials     1367     1373       +6     

see 13 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@fhibf fhibf added Bug Bug bug bug. Azure API for FHIR Label denotes that the issue or PR is relevant to the Azure API for FHIR Azure Healthcare APIs Label denotes that the issue or PR is relevant to the FHIR service in the Azure Healthcare APIs No-PaaS-breaking-change No-ADR ADR not needed labels May 29, 2026
@fhibf fhibf added this to the FY26\Q4\2Wk\2Wk24 milestone May 29, 2026
@fhibf fhibf changed the title [Bundles] Handle operations canceled by client errors as HTTP400 [Bundles] Handle operations cancelled by client errors as HTTP400 May 29, 2026
@fhibf fhibf changed the title [Bundles] Handle operations cancelled by client errors as HTTP400 [Bundles] Handle client errors as HTTP400 May 29, 2026
@fhibf fhibf changed the title [Bundles] Handle client errors as HTTP400 [Bundles] Ensure client errors are HTTP400 May 29, 2026
{
// Ensure that, if a transaction fails with a client error, then the exception with the customer error type is prioritized.
// In the following code, we are prioritizing exceptions of type FhirTransactionFailedException.
FhirTransactionFailedException customerException = aggregateException.InnerExceptions
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Do we define what is client exception anywhere? Is there a centralized list? Could be an opprotunity to define somewhere in the future :)

Example - do we return 410 (gone) if a customer is doing a versioned request and the version is not there?

};
}

// Second entry: no handler set, simulating a route that was not resolved.
Copy link
Copy Markdown
Contributor

@mikaelweave mikaelweave May 29, 2026

Choose a reason for hiding this comment

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

Will other entries return a 404? Since these are all client errors too would it be best to return a 200 which is not a client error? The method that chooses the return exception takes the first that matches - so this tests depends on that first behavior to return the correct exception. Probably okay - but wondering if this test is fully accurate per the title. :)

/// <summary>
/// Given a list of exceptions raised during a bundle execution, prioritizes the exceptions of type <see cref="FhirTransactionFailedException"/>, based on their status code, to determine which exception should be returned to the customer.
/// </summary>
public static FhirTransactionFailedException GetPrioritizedClientException(Exception exception)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Should we add any unit tests for this class?

{
// Ensure that, if a transaction fails with a client error, then the exception with the customer error type is prioritized.
// In the following code, we are prioritizing exceptions of type FhirTransactionFailedException.
FhirTransactionFailedException customerException = aggregateException.InnerExceptions
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

How deep can the exceptions go? If we go lower than on level of nesting should ew use Flatten?

https://learn.microsoft.com/en-us/dotnet/api/system.aggregateexception.flatten?view=netstandard-2.1

get;
}

public bool IsTransactionFailedByClientCancellation => _transactionFailedByClientCancellation == 1;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

do we use this anywhere?


FhirResponse<Bundle> bundleResponse = await _client.PostBundleAsync(bundle, new FhirBundleOptions() { BundleProcessingLogic = processingLogic });

Assert.True(bundleResponse.StatusCode == HttpStatusCode.OK, "HTTP Status code is different than HTTP200.");
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

nit - Assert.Equal is more correct


private sealed class BundleExecutionContext
{
private int _transactionFailedByClientCancellation;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Is this read anywhere?


public bool IsTransactionFailedByClientCancellation => _transactionFailedByClientCancellation == 1;

public bool IsTransactionFailedByClientError => _transactionFailedByClientError == 1;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Should we use a volatile read here for some extra safety?

Suggested change
public bool IsTransactionFailedByClientError => _transactionFailedByClientError == 1;
public bool IsTransactionFailedByClientError => Volatile.Read(ref _transactionFailedByClientError) == 1;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Azure API for FHIR Label denotes that the issue or PR is relevant to the Azure API for FHIR Azure Healthcare APIs Label denotes that the issue or PR is relevant to the FHIR service in the Azure Healthcare APIs Bug Bug bug bug. No-ADR ADR not needed No-PaaS-breaking-change

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants