Skip to content

Commit 65b15cc

Browse files
committed
[csharp][restsharp] guard throwOnAnyError against null FinalException
Polly's PolicyResult.FinalException is null when Outcome is Failure but the failure type is ResultHandledByThisPolicy (e.g. a retry policy configured with .HandleResult(...) that gives up after N retries). Throwing it directly would NRE; fall back to InvalidOperationException so the option still surfaces an error. Also restores the trailing whitespace on the if line so existing restsharp samples don't all need regenerating.
1 parent c19a3f7 commit 65b15cc

2 files changed

Lines changed: 4 additions & 4 deletions

File tree

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -561,14 +561,14 @@ 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
{
570570
{{#throwOnAnyError}}
571-
throw policyResult.FinalException;
571+
throw policyResult.FinalException ?? new InvalidOperationException("The retry policy failed without an exception.");
572572
{{/throwOnAnyError}}
573573
{{^throwOnAnyError}}
574574
return new RestResponse<T>(request)

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -552,14 +552,14 @@ 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
{
561561
{{#throwOnAnyError}}
562-
throw policyResult.FinalException;
562+
throw policyResult.FinalException ?? new InvalidOperationException("The retry policy failed without an exception.");
563563
{{/throwOnAnyError}}
564564
{{^throwOnAnyError}}
565565
return new RestResponse<T>(request)

0 commit comments

Comments
 (0)