Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/generators/csharp.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl
|returnICollection|Return ICollection<T> instead of the concrete type.| |false|
|sourceFolder|source folder for generated code| |src|
|targetFramework|The target .NET framework version. To target multiple frameworks, use `;` as the separator, e.g. `netstandard2.1;netcoreapp3.1`|<dl><dt>**netstandard1.3**</dt><dd>.NET Standard 1.3</dd><dt>**netstandard1.4**</dt><dd>.NET Standard 1.4</dd><dt>**netstandard1.5**</dt><dd>.NET Standard 1.5</dd><dt>**netstandard1.6**</dt><dd>.NET Standard 1.6</dd><dt>**netstandard2.0**</dt><dd>.NET Standard 2.0</dd><dt>**netstandard2.1**</dt><dd>.NET Standard 2.1</dd><dt>**net47**</dt><dd>.NET Framework 4.7</dd><dt>**net48**</dt><dd>.NET Framework 4.8</dd><dt>**net8.0**</dt><dd>.NET 8.0 (End of Support 10 November 2026)</dd><dt>**net9.0**</dt><dd>.NET 9.0 (End of Support 10 November 2026)</dd><dt>**net10.0**</dt><dd>.NET 10.0 (End of Support 14 November 2028)</dd></dl>|net10.0|
|throwOnAnyError|Configure RestSharp to rethrow deserialization and transport errors instead of swallowing them into RestResponse.ErrorException (which the default ToApiResponse&lt;T&gt; discards as null Data). Recommended for production use to surface bugs that would otherwise be invisible. (restsharp only)| |false|
|throwOnAnyError|Throw ApiException on deserialization and transport errors instead of swallowing them into RestResponse.ErrorException (which the default ToApiResponse&lt;T&gt; discards as null Data). HTTP error statuses keep going through ExceptionFactory. Recommended for production use to surface bugs that would otherwise be invisible. (restsharp only)| |false|
|useCollection|Deserialize array types to Collection&lt;T&gt; instead of List&lt;T&gt;.| |false|
|useDateTimeForDate|Use DateTime to model date properties even if DateOnly supported. (.net 6.0+ only)| |false|
|useDateTimeOffset|Use DateTimeOffset to model date-time properties| |false|
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ public CSharpClientCodegen() {
String.valueOf(this.useIntForTimeout));

addSwitch(CSharpClientCodegen.THROW_ON_ANY_ERROR,
"Configure RestSharp to rethrow deserialization and transport errors instead of swallowing them into RestResponse.ErrorException (which the default ToApiResponse<T> discards as null Data). Recommended for production use to surface bugs that would otherwise be invisible. (restsharp only)",
"Throw ApiException on deserialization and transport errors instead of swallowing them into RestResponse.ErrorException (which the default ToApiResponse<T> discards as null Data). HTTP error statuses keep going through ExceptionFactory. Recommended for production use to surface bugs that would otherwise be invisible. (restsharp only)",
this.throwOnAnyError);

CliOption framework = new CliOption(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -467,8 +467,7 @@ namespace {{packageName}}.Client
Proxy = configuration.Proxy,
UserAgent = configuration.UserAgent,
UseDefaultCredentials = configuration.UseDefaultCredentials,
RemoteCertificateValidationCallback = configuration.RemoteCertificateValidationCallback{{#throwOnAnyError}},
ThrowOnAnyError = true{{/throwOnAnyError}}
RemoteCertificateValidationCallback = configuration.RemoteCertificateValidationCallback
};
setOptions(clientOptions);

Expand All @@ -495,6 +494,14 @@ namespace {{packageName}}.Client
InterceptRequest(request);

RestResponse<T> response = await getResponse(client).ConfigureAwait(false);
{{#throwOnAnyError}}

// 4xx/5xx also carry ErrorException; those go through ExceptionFactory so the body is kept
if (response.ErrorException != null && (int)response.StatusCode < 400)
Comment thread
mszopa-foss marked this conversation as resolved.
{
throw new ApiException((int)response.StatusCode, string.Format("Error calling {0}: {1}", request.Resource, response.ErrorException.Message), response.Content, ToApiResponse(response).Headers, response.ErrorException);
}
{{/throwOnAnyError}}

// if the response type is oneOf/anyOf, call FromJSON to deserialize the data
if (typeof(AbstractOpenAPISchema).IsAssignableFrom(typeof(T)))
Expand Down Expand Up @@ -567,15 +574,10 @@ namespace {{packageName}}.Client
}
else
{
{{#throwOnAnyError}}
throw policyResult.FinalException ?? new InvalidOperationException("The retry policy failed without an exception.");
{{/throwOnAnyError}}
{{^throwOnAnyError}}
return new RestResponse<T>(request)
{
ErrorException = policyResult.FinalException
};
{{/throwOnAnyError}}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -486,6 +486,14 @@ namespace {{packageName}}.Client
InterceptRequest(request);

RestResponse<T> response = await getResponse(client);
{{#throwOnAnyError}}

// 4xx/5xx also carry ErrorException; those go through ExceptionFactory so the body is kept
if (response.ErrorException != null && (int)response.StatusCode < 400)
{
throw new ApiException((int)response.StatusCode, string.Format("Error calling {0}: {1}", request.Resource, response.ErrorException.Message), response.Content, ToApiResponse(response).Headers, response.ErrorException);
}
{{/throwOnAnyError}}

// if the response type is oneOf/anyOf, call FromJSON to deserialize the data
if (typeof(AbstractOpenAPISchema).IsAssignableFrom(typeof(T)))
Expand Down Expand Up @@ -558,15 +566,10 @@ namespace {{packageName}}.Client
}
else
{
{{#throwOnAnyError}}
throw policyResult.FinalException ?? new InvalidOperationException("The retry policy failed without an exception.");
{{/throwOnAnyError}}
{{^throwOnAnyError}}
return new RestResponse<T>(request)
{
ErrorException = policyResult.FinalException
};
{{/throwOnAnyError}}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,17 @@ namespace {{packageName}}.Client
/// <param name="message">Error message.</param>
/// <param name="errorContent">Error content.</param>
/// <param name="headers">HTTP Headers.</param>
public ApiException(int errorCode, string message, object errorContent = null, Multimap<string, string> headers = null) : base(message)
public ApiException(int errorCode, string message, object errorContent = null, Multimap<string, string> headers = null) : this(errorCode, message, errorContent, headers, null) { }

/// <summary>
/// Initializes a new instance of the <see cref="ApiException"/> class.
/// </summary>
/// <param name="errorCode">HTTP status code.</param>
/// <param name="message">Error message.</param>
/// <param name="errorContent">Error content.</param>
/// <param name="headers">HTTP Headers.</param>
/// <param name="innerException">The exception that caused this error.</param>
public ApiException(int errorCode, string message, object errorContent, Multimap<string, string> headers, Exception innerException) : base(message, innerException)
{
this.ErrorCode = errorCode;
this.ErrorContent = errorContent;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,17 @@ public ApiException(int errorCode, string message) : base(message)
/// <param name="message">Error message.</param>
/// <param name="errorContent">Error content.</param>
/// <param name="headers">HTTP Headers.</param>
public ApiException(int errorCode, string message, object errorContent = null, Multimap<string, string> headers = null) : base(message)
public ApiException(int errorCode, string message, object errorContent = null, Multimap<string, string> headers = null) : this(errorCode, message, errorContent, headers, null) { }

/// <summary>
/// Initializes a new instance of the <see cref="ApiException"/> class.
/// </summary>
/// <param name="errorCode">HTTP status code.</param>
/// <param name="message">Error message.</param>
/// <param name="errorContent">Error content.</param>
/// <param name="headers">HTTP Headers.</param>
/// <param name="innerException">The exception that caused this error.</param>
public ApiException(int errorCode, string message, object errorContent, Multimap<string, string> headers, Exception innerException) : base(message, innerException)
{
this.ErrorCode = errorCode;
this.ErrorContent = errorContent;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,17 @@ public ApiException(int errorCode, string message) : base(message)
/// <param name="message">Error message.</param>
/// <param name="errorContent">Error content.</param>
/// <param name="headers">HTTP Headers.</param>
public ApiException(int errorCode, string message, object errorContent = null, Multimap<string, string> headers = null) : base(message)
public ApiException(int errorCode, string message, object errorContent = null, Multimap<string, string> headers = null) : this(errorCode, message, errorContent, headers, null) { }

/// <summary>
/// Initializes a new instance of the <see cref="ApiException"/> class.
/// </summary>
/// <param name="errorCode">HTTP status code.</param>
/// <param name="message">Error message.</param>
/// <param name="errorContent">Error content.</param>
/// <param name="headers">HTTP Headers.</param>
/// <param name="innerException">The exception that caused this error.</param>
public ApiException(int errorCode, string message, object errorContent, Multimap<string, string> headers, Exception innerException) : base(message, innerException)
{
this.ErrorCode = errorCode;
this.ErrorContent = errorContent;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,17 @@ public ApiException(int errorCode, string message) : base(message)
/// <param name="message">Error message.</param>
/// <param name="errorContent">Error content.</param>
/// <param name="headers">HTTP Headers.</param>
public ApiException(int errorCode, string message, object errorContent = null, Multimap<string, string> headers = null) : base(message)
public ApiException(int errorCode, string message, object errorContent = null, Multimap<string, string> headers = null) : this(errorCode, message, errorContent, headers, null) { }

/// <summary>
/// Initializes a new instance of the <see cref="ApiException"/> class.
/// </summary>
/// <param name="errorCode">HTTP status code.</param>
/// <param name="message">Error message.</param>
/// <param name="errorContent">Error content.</param>
/// <param name="headers">HTTP Headers.</param>
/// <param name="innerException">The exception that caused this error.</param>
public ApiException(int errorCode, string message, object errorContent, Multimap<string, string> headers, Exception innerException) : base(message, innerException)
{
this.ErrorCode = errorCode;
this.ErrorContent = errorContent;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,17 @@ public ApiException(int errorCode, string message) : base(message)
/// <param name="message">Error message.</param>
/// <param name="errorContent">Error content.</param>
/// <param name="headers">HTTP Headers.</param>
public ApiException(int errorCode, string message, object errorContent = null, Multimap<string, string> headers = null) : base(message)
public ApiException(int errorCode, string message, object errorContent = null, Multimap<string, string> headers = null) : this(errorCode, message, errorContent, headers, null) { }

/// <summary>
/// Initializes a new instance of the <see cref="ApiException"/> class.
/// </summary>
/// <param name="errorCode">HTTP status code.</param>
/// <param name="message">Error message.</param>
/// <param name="errorContent">Error content.</param>
/// <param name="headers">HTTP Headers.</param>
/// <param name="innerException">The exception that caused this error.</param>
public ApiException(int errorCode, string message, object errorContent, Multimap<string, string> headers, Exception innerException) : base(message, innerException)
{
this.ErrorCode = errorCode;
this.ErrorContent = errorContent;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,17 @@ public ApiException(int errorCode, string message) : base(message)
/// <param name="message">Error message.</param>
/// <param name="errorContent">Error content.</param>
/// <param name="headers">HTTP Headers.</param>
public ApiException(int errorCode, string message, object errorContent = null, Multimap<string, string> headers = null) : base(message)
public ApiException(int errorCode, string message, object errorContent = null, Multimap<string, string> headers = null) : this(errorCode, message, errorContent, headers, null) { }

/// <summary>
/// Initializes a new instance of the <see cref="ApiException"/> class.
/// </summary>
/// <param name="errorCode">HTTP status code.</param>
/// <param name="message">Error message.</param>
/// <param name="errorContent">Error content.</param>
/// <param name="headers">HTTP Headers.</param>
/// <param name="innerException">The exception that caused this error.</param>
public ApiException(int errorCode, string message, object errorContent, Multimap<string, string> headers, Exception innerException) : base(message, innerException)
{
this.ErrorCode = errorCode;
this.ErrorContent = errorContent;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,17 @@ public ApiException(int errorCode, string message) : base(message)
/// <param name="message">Error message.</param>
/// <param name="errorContent">Error content.</param>
/// <param name="headers">HTTP Headers.</param>
public ApiException(int errorCode, string message, object errorContent = null, Multimap<string, string> headers = null) : base(message)
public ApiException(int errorCode, string message, object errorContent = null, Multimap<string, string> headers = null) : this(errorCode, message, errorContent, headers, null) { }

/// <summary>
/// Initializes a new instance of the <see cref="ApiException"/> class.
/// </summary>
/// <param name="errorCode">HTTP status code.</param>
/// <param name="message">Error message.</param>
/// <param name="errorContent">Error content.</param>
/// <param name="headers">HTTP Headers.</param>
/// <param name="innerException">The exception that caused this error.</param>
public ApiException(int errorCode, string message, object errorContent, Multimap<string, string> headers, Exception innerException) : base(message, innerException)
{
this.ErrorCode = errorCode;
this.ErrorContent = errorContent;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,17 @@ public ApiException(int errorCode, string message) : base(message)
/// <param name="message">Error message.</param>
/// <param name="errorContent">Error content.</param>
/// <param name="headers">HTTP Headers.</param>
public ApiException(int errorCode, string message, object errorContent = null, Multimap<string, string> headers = null) : base(message)
public ApiException(int errorCode, string message, object errorContent = null, Multimap<string, string> headers = null) : this(errorCode, message, errorContent, headers, null) { }

/// <summary>
/// Initializes a new instance of the <see cref="ApiException"/> class.
/// </summary>
/// <param name="errorCode">HTTP status code.</param>
/// <param name="message">Error message.</param>
/// <param name="errorContent">Error content.</param>
/// <param name="headers">HTTP Headers.</param>
/// <param name="innerException">The exception that caused this error.</param>
public ApiException(int errorCode, string message, object errorContent, Multimap<string, string> headers, Exception innerException) : base(message, innerException)
{
this.ErrorCode = errorCode;
this.ErrorContent = errorContent;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,17 @@ public ApiException(int errorCode, string message) : base(message)
/// <param name="message">Error message.</param>
/// <param name="errorContent">Error content.</param>
/// <param name="headers">HTTP Headers.</param>
public ApiException(int errorCode, string message, object errorContent = null, Multimap<string, string> headers = null) : base(message)
public ApiException(int errorCode, string message, object errorContent = null, Multimap<string, string> headers = null) : this(errorCode, message, errorContent, headers, null) { }

/// <summary>
/// Initializes a new instance of the <see cref="ApiException"/> class.
/// </summary>
/// <param name="errorCode">HTTP status code.</param>
/// <param name="message">Error message.</param>
/// <param name="errorContent">Error content.</param>
/// <param name="headers">HTTP Headers.</param>
/// <param name="innerException">The exception that caused this error.</param>
public ApiException(int errorCode, string message, object errorContent, Multimap<string, string> headers, Exception innerException) : base(message, innerException)
{
this.ErrorCode = errorCode;
this.ErrorContent = errorContent;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,17 @@ public ApiException(int errorCode, string message) : base(message)
/// <param name="message">Error message.</param>
/// <param name="errorContent">Error content.</param>
/// <param name="headers">HTTP Headers.</param>
public ApiException(int errorCode, string message, object errorContent = null, Multimap<string, string> headers = null) : base(message)
public ApiException(int errorCode, string message, object errorContent = null, Multimap<string, string> headers = null) : this(errorCode, message, errorContent, headers, null) { }

/// <summary>
/// Initializes a new instance of the <see cref="ApiException"/> class.
/// </summary>
/// <param name="errorCode">HTTP status code.</param>
/// <param name="message">Error message.</param>
/// <param name="errorContent">Error content.</param>
/// <param name="headers">HTTP Headers.</param>
/// <param name="innerException">The exception that caused this error.</param>
public ApiException(int errorCode, string message, object errorContent, Multimap<string, string> headers, Exception innerException) : base(message, innerException)
{
this.ErrorCode = errorCode;
this.ErrorContent = errorContent;
Expand Down
Loading
Loading