Commit f87373c
authored
[csharp][restsharp] add throwOnAnyError option to surface client errors (OpenAPITools#23663)
* [csharp][restsharp] add throwOnAnyError option to surface client errors
By default, RestSharp swallows deserialization and transport
exceptions into RestResponse.ErrorException, and the generated
ToApiResponse<T> in this template only carries ErrorText — the
actual exception is dropped. Combined with a generated GetXxxAsync
that returns Data directly, callers silently receive null on any
deserialization failure (e.g. a required property missing in the
upstream JSON). The error never reaches application logs or APM.
Add an opt-in `throwOnAnyError` switch (default false, restsharp
library only) that sets `ThrowOnAnyError = true` on RestClientOptions,
making RestSharp rethrow the original ApiException(500, ...) that
the generated deserializer already throws. The exception then
propagates to the caller and into normal application error handling.
Default kept off to preserve backwards compatibility — opt in when
you want bugs to surface instead of silently producing null/[].
* docs: regenerate csharp.md to alphabetical order
* [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.
* [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 2bb7296 commit f87373c
4 files changed
Lines changed: 24 additions & 1 deletion
File tree
- docs/generators
- modules/openapi-generator/src/main
- java/org/openapitools/codegen/languages
- resources/csharp
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
47 | 47 | | |
48 | 48 | | |
49 | 49 | | |
| 50 | + | |
50 | 51 | | |
51 | 52 | | |
52 | 53 | | |
| |||
Lines changed: 11 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
122 | 122 | | |
123 | 123 | | |
124 | 124 | | |
| 125 | + | |
125 | 126 | | |
126 | 127 | | |
127 | 128 | | |
| |||
132 | 133 | | |
133 | 134 | | |
134 | 135 | | |
| 136 | + | |
135 | 137 | | |
136 | 138 | | |
137 | 139 | | |
| |||
249 | 251 | | |
250 | 252 | | |
251 | 253 | | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
252 | 258 | | |
253 | 259 | | |
254 | 260 | | |
| |||
871 | 877 | | |
872 | 878 | | |
873 | 879 | | |
| 880 | + | |
874 | 881 | | |
875 | 882 | | |
876 | 883 | | |
| |||
1244 | 1251 | | |
1245 | 1252 | | |
1246 | 1253 | | |
| 1254 | + | |
| 1255 | + | |
| 1256 | + | |
| 1257 | + | |
1247 | 1258 | | |
1248 | 1259 | | |
1249 | 1260 | | |
| |||
Lines changed: 7 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
467 | 467 | | |
468 | 468 | | |
469 | 469 | | |
470 | | - | |
| 470 | + | |
| 471 | + | |
471 | 472 | | |
472 | 473 | | |
473 | 474 | | |
| |||
566 | 567 | | |
567 | 568 | | |
568 | 569 | | |
| 570 | + | |
| 571 | + | |
| 572 | + | |
| 573 | + | |
569 | 574 | | |
570 | 575 | | |
571 | 576 | | |
572 | 577 | | |
| 578 | + | |
573 | 579 | | |
574 | 580 | | |
575 | 581 | | |
| |||
Lines changed: 5 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
558 | 558 | | |
559 | 559 | | |
560 | 560 | | |
| 561 | + | |
| 562 | + | |
| 563 | + | |
| 564 | + | |
561 | 565 | | |
562 | 566 | | |
563 | 567 | | |
564 | 568 | | |
| 569 | + | |
565 | 570 | | |
566 | 571 | | |
567 | 572 | | |
| |||
0 commit comments