Skip to content

Commit c19a3f7

Browse files
committed
[csharp][restsharp] honour throwOnAnyError when retry policy is configured
Polly's ExecuteAndCapture catches the rethrown ApiException, so without this change the option is silently neutralized whenever RetryConfiguration.RetryPolicy != null: the exception ends up in RestResponse.ErrorException, which ToApiResponse discards. When throwOnAnyError is enabled, rethrow PolicyResult.FinalException from DeserializeRestResponseFromPolicyAsync so the contract is consistent across both the no-retry and retry paths. Default-off branch is byte-identical to the previous output.
1 parent fe704b5 commit c19a3f7

2 files changed

Lines changed: 12 additions & 2 deletions

File tree

modules/openapi-generator/src/main/resources/csharp/ApiClient.mustache

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -561,16 +561,21 @@ namespace {{packageName}}.Client
561561
562562
private async Task<RestResponse<T>> DeserializeRestResponseFromPolicyAsync<T>(RestClient client, RestRequest request, PolicyResult<RestResponse> policyResult, CancellationToken cancellationToken = default)
563563
{
564-
if (policyResult.Outcome == OutcomeType.Successful)
564+
if (policyResult.Outcome == OutcomeType.Successful)
565565
{
566566
return await client.Deserialize<T>(policyResult.Result, cancellationToken).ConfigureAwait(false);
567567
}
568568
else
569569
{
570+
{{#throwOnAnyError}}
571+
throw policyResult.FinalException;
572+
{{/throwOnAnyError}}
573+
{{^throwOnAnyError}}
570574
return new RestResponse<T>(request)
571575
{
572576
ErrorException = policyResult.FinalException
573577
};
578+
{{/throwOnAnyError}}
574579
}
575580
}
576581

modules/openapi-generator/src/main/resources/csharp/ApiClient.v790.mustache

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -552,16 +552,21 @@ namespace {{packageName}}.Client
552552
553553
private async Task<RestResponse<T>> DeserializeRestResponseFromPolicyAsync<T>(RestClient client, RestRequest request, PolicyResult<RestResponse> policyResult, CancellationToken cancellationToken = default)
554554
{
555-
if (policyResult.Outcome == OutcomeType.Successful)
555+
if (policyResult.Outcome == OutcomeType.Successful)
556556
{
557557
return await client.Deserialize<T>(policyResult.Result, cancellationToken);
558558
}
559559
else
560560
{
561+
{{#throwOnAnyError}}
562+
throw policyResult.FinalException;
563+
{{/throwOnAnyError}}
564+
{{^throwOnAnyError}}
561565
return new RestResponse<T>(request)
562566
{
563567
ErrorException = policyResult.FinalException
564568
};
569+
{{/throwOnAnyError}}
565570
}
566571
}
567572

0 commit comments

Comments
 (0)