Skip to content

Commit 0300601

Browse files
committed
feat: Also wrap JSON deserialization exception from error responses.
1 parent cd7bf3e commit 0300601

File tree

4,368 files changed

+142562
-55109
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

4,368 files changed

+142562
-55109
lines changed

src/libs/AutoSDK/Sources/Sources.Exceptions.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ public ApiException(string message, global::System.Net.HttpStatusCode statusCode
6060
/// <param name=""message"">The error message that explains the reason for the exception.</param>
6161
/// <param name=""innerException"">The exception that is the cause of the current exception, or a null reference if no inner exception is specified.</param>
6262
/// <param name=""statusCode"">The HTTP status code of the response.</param>
63-
public ApiException(string message, global::System.Exception innerException, global::System.Net.HttpStatusCode statusCode) : base(message, innerException)
63+
public ApiException(string message, global::System.Exception? innerException, global::System.Net.HttpStatusCode statusCode) : base(message, innerException)
6464
{{
6565
StatusCode = statusCode;
6666
}}
@@ -100,7 +100,7 @@ public ApiException(string message, global::System.Net.HttpStatusCode statusCode
100100
/// <param name=""message"">The error message that explains the reason for the exception.</param>
101101
/// <param name=""innerException"">The exception that is the cause of the current exception, or a null reference if no inner exception is specified.</param>
102102
/// <param name=""statusCode"">The HTTP status code of the response.</param>
103-
public ApiException(string message, global::System.Exception innerException, global::System.Net.HttpStatusCode statusCode) : base(message, innerException, statusCode)
103+
public ApiException(string message, global::System.Exception? innerException, global::System.Net.HttpStatusCode statusCode) : base(message, innerException, statusCode)
104104
{{
105105
}}
106106
}}

src/libs/AutoSDK/Sources/Sources.Methods.cs

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -374,25 +374,34 @@ public static string GenerateResponse(
374374
if ((int)__response.StatusCode == {x.StatusCode})")}
375375
{{
376376
string? __content_{x.StatusCode} = null;
377+
global::System.Exception? __exception_{x.StatusCode} = null;
377378
{(!string.IsNullOrWhiteSpace(x.Type.CSharpTypeWithoutNullability) ? $@"
378379
{x.Type.CSharpTypeWithoutNullability}? __value_{x.StatusCode} = null;" : " ")}
379-
if (ReadResponseAsString)
380+
try
380381
{{
381-
__content_{x.StatusCode} = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false);
382+
if (ReadResponseAsString)
383+
{{
384+
__content_{x.StatusCode} = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false);
385+
{(!string.IsNullOrWhiteSpace(x.Type.CSharpTypeWithoutNullability) ? $@"
386+
__value_{x.StatusCode} = {jsonSerializer.GenerateDeserializeCall($"__content_{x.StatusCode}", x.Type, endPoint.Settings.JsonSerializerContext)};" : " ")}
387+
}}
388+
else
389+
{{
390+
var __contentStream_{x.StatusCode} = await __response.Content.ReadAsStreamAsync(cancellationToken).ConfigureAwait(false);
382391
{(!string.IsNullOrWhiteSpace(x.Type.CSharpTypeWithoutNullability) ? $@"
383-
__value_{x.StatusCode} = {jsonSerializer.GenerateDeserializeCall($"__content_{x.StatusCode}", x.Type, endPoint.Settings.JsonSerializerContext)};" : " ")}
392+
__value_{x.StatusCode} = {jsonSerializer.GenerateDeserializeFromStreamCall($"__contentStream_{x.StatusCode}", x.Type, endPoint.Settings.JsonSerializerContext)};" : " ")}
393+
}}
384394
}}
385-
else
395+
catch (global::System.Exception __ex)
386396
{{
387-
var __contentStream_{x.StatusCode} = await __response.Content.ReadAsStreamAsync(cancellationToken).ConfigureAwait(false);
388-
{(!string.IsNullOrWhiteSpace(x.Type.CSharpTypeWithoutNullability) ? $@"
389-
__value_{x.StatusCode} = {jsonSerializer.GenerateDeserializeFromStreamCall($"__contentStream_{x.StatusCode}", x.Type, endPoint.Settings.JsonSerializerContext)};" : " ")}
397+
__exception_{x.StatusCode} = __ex;
390398
}}
391399
392400
{(!string.IsNullOrWhiteSpace(x.Type.CSharpTypeWithoutNullability) ? $@"
393401
throw new global::{endPoint.GlobalSettings.Namespace}.ApiException<{x.Type.CSharpTypeWithNullabilityForValueTypes}>(" : $@"
394402
throw new global::{endPoint.GlobalSettings.Namespace}.ApiException(")}
395403
message: __content_{x.StatusCode} ?? __response.ReasonPhrase ?? string.Empty,
404+
innerException: __exception_{x.StatusCode},
396405
statusCode: __response.StatusCode)
397406
{{
398407
ResponseBody = __content_{x.StatusCode},

src/tests/AutoSDK.SnapshotTests/Snapshots/Empty/NewtonsoftJson/_#G.Exceptions.g.verified.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public ApiException(string message, global::System.Net.HttpStatusCode statusCode
4444
/// <param name="message">The error message that explains the reason for the exception.</param>
4545
/// <param name="innerException">The exception that is the cause of the current exception, or a null reference if no inner exception is specified.</param>
4646
/// <param name="statusCode">The HTTP status code of the response.</param>
47-
public ApiException(string message, global::System.Exception innerException, global::System.Net.HttpStatusCode statusCode) : base(message, innerException)
47+
public ApiException(string message, global::System.Exception? innerException, global::System.Net.HttpStatusCode statusCode) : base(message, innerException)
4848
{
4949
StatusCode = statusCode;
5050
}
@@ -84,7 +84,7 @@ public ApiException(string message, global::System.Net.HttpStatusCode statusCode
8484
/// <param name="message">The error message that explains the reason for the exception.</param>
8585
/// <param name="innerException">The exception that is the cause of the current exception, or a null reference if no inner exception is specified.</param>
8686
/// <param name="statusCode">The HTTP status code of the response.</param>
87-
public ApiException(string message, global::System.Exception innerException, global::System.Net.HttpStatusCode statusCode) : base(message, innerException, statusCode)
87+
public ApiException(string message, global::System.Exception? innerException, global::System.Net.HttpStatusCode statusCode) : base(message, innerException, statusCode)
8888
{
8989
}
9090
}

src/tests/AutoSDK.SnapshotTests/Snapshots/Empty/SystemTextJson/_#G.Exceptions.g.verified.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public ApiException(string message, global::System.Net.HttpStatusCode statusCode
4444
/// <param name="message">The error message that explains the reason for the exception.</param>
4545
/// <param name="innerException">The exception that is the cause of the current exception, or a null reference if no inner exception is specified.</param>
4646
/// <param name="statusCode">The HTTP status code of the response.</param>
47-
public ApiException(string message, global::System.Exception innerException, global::System.Net.HttpStatusCode statusCode) : base(message, innerException)
47+
public ApiException(string message, global::System.Exception? innerException, global::System.Net.HttpStatusCode statusCode) : base(message, innerException)
4848
{
4949
StatusCode = statusCode;
5050
}
@@ -84,7 +84,7 @@ public ApiException(string message, global::System.Net.HttpStatusCode statusCode
8484
/// <param name="message">The error message that explains the reason for the exception.</param>
8585
/// <param name="innerException">The exception that is the cause of the current exception, or a null reference if no inner exception is specified.</param>
8686
/// <param name="statusCode">The HTTP status code of the response.</param>
87-
public ApiException(string message, global::System.Exception innerException, global::System.Net.HttpStatusCode statusCode) : base(message, innerException, statusCode)
87+
public ApiException(string message, global::System.Exception? innerException, global::System.Net.HttpStatusCode statusCode) : base(message, innerException, statusCode)
8888
{
8989
}
9090
}

src/tests/AutoSDK.SnapshotTests/Snapshots/ai21/NewtonsoftJson/_#G.Api.ConvertDocumentFileStudioV1ChatFilesConvertPost.g.verified.cs

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -97,20 +97,29 @@ partial void ProcessConvertDocumentFileStudioV1ChatFilesConvertPostResponseConte
9797
if ((int)__response.StatusCode == 422)
9898
{
9999
string? __content_422 = null;
100+
global::System.Exception? __exception_422 = null;
100101
global::G.HTTPValidationError? __value_422 = null;
101-
if (ReadResponseAsString)
102+
try
102103
{
103-
__content_422 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false);
104-
__value_422 = global::G.HTTPValidationError.FromJson(__content_422, JsonSerializerOptions);
104+
if (ReadResponseAsString)
105+
{
106+
__content_422 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false);
107+
__value_422 = global::G.HTTPValidationError.FromJson(__content_422, JsonSerializerOptions);
108+
}
109+
else
110+
{
111+
var __contentStream_422 = await __response.Content.ReadAsStreamAsync(cancellationToken).ConfigureAwait(false);
112+
__value_422 = await global::G.HTTPValidationError.FromJsonStreamAsync(__contentStream_422, JsonSerializerOptions).ConfigureAwait(false);
113+
}
105114
}
106-
else
115+
catch (global::System.Exception __ex)
107116
{
108-
var __contentStream_422 = await __response.Content.ReadAsStreamAsync(cancellationToken).ConfigureAwait(false);
109-
__value_422 = await global::G.HTTPValidationError.FromJsonStreamAsync(__contentStream_422, JsonSerializerOptions).ConfigureAwait(false);
117+
__exception_422 = __ex;
110118
}
111119

112120
throw new global::G.ApiException<global::G.HTTPValidationError>(
113121
message: __content_422 ?? __response.ReasonPhrase ?? string.Empty,
122+
innerException: __exception_422,
114123
statusCode: __response.StatusCode)
115124
{
116125
ResponseBody = __content_422,

src/tests/AutoSDK.SnapshotTests/Snapshots/ai21/NewtonsoftJson/_#G.Api.GenerateOrgTokenStudioV1ConnectorsConnectedUsersOrganizationIdTokensPost.g.verified.cs

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -84,20 +84,29 @@ partial void ProcessGenerateOrgTokenStudioV1ConnectorsConnectedUsersOrganization
8484
if ((int)__response.StatusCode == 422)
8585
{
8686
string? __content_422 = null;
87+
global::System.Exception? __exception_422 = null;
8788
global::G.HTTPValidationError? __value_422 = null;
88-
if (ReadResponseAsString)
89+
try
8990
{
90-
__content_422 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false);
91-
__value_422 = global::G.HTTPValidationError.FromJson(__content_422, JsonSerializerOptions);
91+
if (ReadResponseAsString)
92+
{
93+
__content_422 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false);
94+
__value_422 = global::G.HTTPValidationError.FromJson(__content_422, JsonSerializerOptions);
95+
}
96+
else
97+
{
98+
var __contentStream_422 = await __response.Content.ReadAsStreamAsync(cancellationToken).ConfigureAwait(false);
99+
__value_422 = await global::G.HTTPValidationError.FromJsonStreamAsync(__contentStream_422, JsonSerializerOptions).ConfigureAwait(false);
100+
}
92101
}
93-
else
102+
catch (global::System.Exception __ex)
94103
{
95-
var __contentStream_422 = await __response.Content.ReadAsStreamAsync(cancellationToken).ConfigureAwait(false);
96-
__value_422 = await global::G.HTTPValidationError.FromJsonStreamAsync(__contentStream_422, JsonSerializerOptions).ConfigureAwait(false);
104+
__exception_422 = __ex;
97105
}
98106

99107
throw new global::G.ApiException<global::G.HTTPValidationError>(
100108
message: __content_422 ?? __response.ReasonPhrase ?? string.Empty,
109+
innerException: __exception_422,
101110
statusCode: __response.StatusCode)
102111
{
103112
ResponseBody = __content_422,

src/tests/AutoSDK.SnapshotTests/Snapshots/ai21/NewtonsoftJson/_#G.Api.GetDataSourceStatusStudioV1ConnectorsConnectedUsersOrganizationIdDataSourcesDataSourceStatusGet.g.verified.cs

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -90,20 +90,29 @@ partial void ProcessGetDataSourceStatusStudioV1ConnectorsConnectedUsersOrganizat
9090
if ((int)__response.StatusCode == 422)
9191
{
9292
string? __content_422 = null;
93+
global::System.Exception? __exception_422 = null;
9394
global::G.HTTPValidationError? __value_422 = null;
94-
if (ReadResponseAsString)
95+
try
9596
{
96-
__content_422 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false);
97-
__value_422 = global::G.HTTPValidationError.FromJson(__content_422, JsonSerializerOptions);
97+
if (ReadResponseAsString)
98+
{
99+
__content_422 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false);
100+
__value_422 = global::G.HTTPValidationError.FromJson(__content_422, JsonSerializerOptions);
101+
}
102+
else
103+
{
104+
var __contentStream_422 = await __response.Content.ReadAsStreamAsync(cancellationToken).ConfigureAwait(false);
105+
__value_422 = await global::G.HTTPValidationError.FromJsonStreamAsync(__contentStream_422, JsonSerializerOptions).ConfigureAwait(false);
106+
}
98107
}
99-
else
108+
catch (global::System.Exception __ex)
100109
{
101-
var __contentStream_422 = await __response.Content.ReadAsStreamAsync(cancellationToken).ConfigureAwait(false);
102-
__value_422 = await global::G.HTTPValidationError.FromJsonStreamAsync(__contentStream_422, JsonSerializerOptions).ConfigureAwait(false);
110+
__exception_422 = __ex;
103111
}
104112

105113
throw new global::G.ApiException<global::G.HTTPValidationError>(
106114
message: __content_422 ?? __response.ReasonPhrase ?? string.Empty,
115+
innerException: __exception_422,
107116
statusCode: __response.StatusCode)
108117
{
109118
ResponseBody = __content_422,

src/tests/AutoSDK.SnapshotTests/Snapshots/ai21/NewtonsoftJson/_#G.Api.GetOrgDataSourcesInfoStudioV1ConnectorsConnectedUsersOrganizationIdDataSourcesGet.g.verified.cs

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -84,20 +84,29 @@ partial void ProcessGetOrgDataSourcesInfoStudioV1ConnectorsConnectedUsersOrganiz
8484
if ((int)__response.StatusCode == 422)
8585
{
8686
string? __content_422 = null;
87+
global::System.Exception? __exception_422 = null;
8788
global::G.HTTPValidationError? __value_422 = null;
88-
if (ReadResponseAsString)
89+
try
8990
{
90-
__content_422 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false);
91-
__value_422 = global::G.HTTPValidationError.FromJson(__content_422, JsonSerializerOptions);
91+
if (ReadResponseAsString)
92+
{
93+
__content_422 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false);
94+
__value_422 = global::G.HTTPValidationError.FromJson(__content_422, JsonSerializerOptions);
95+
}
96+
else
97+
{
98+
var __contentStream_422 = await __response.Content.ReadAsStreamAsync(cancellationToken).ConfigureAwait(false);
99+
__value_422 = await global::G.HTTPValidationError.FromJsonStreamAsync(__contentStream_422, JsonSerializerOptions).ConfigureAwait(false);
100+
}
92101
}
93-
else
102+
catch (global::System.Exception __ex)
94103
{
95-
var __contentStream_422 = await __response.Content.ReadAsStreamAsync(cancellationToken).ConfigureAwait(false);
96-
__value_422 = await global::G.HTTPValidationError.FromJsonStreamAsync(__contentStream_422, JsonSerializerOptions).ConfigureAwait(false);
104+
__exception_422 = __ex;
97105
}
98106

99107
throw new global::G.ApiException<global::G.HTTPValidationError>(
100108
message: __content_422 ?? __response.ReasonPhrase ?? string.Empty,
109+
innerException: __exception_422,
101110
statusCode: __response.StatusCode)
102111
{
103112
ResponseBody = __content_422,

src/tests/AutoSDK.SnapshotTests/Snapshots/ai21/NewtonsoftJson/_#G.Api.V1ConversationalRag.g.verified.cs

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -92,20 +92,29 @@ partial void ProcessV1ConversationalRagResponseContent(
9292
if ((int)__response.StatusCode == 422)
9393
{
9494
string? __content_422 = null;
95+
global::System.Exception? __exception_422 = null;
9596
global::G.HTTPValidationError? __value_422 = null;
96-
if (ReadResponseAsString)
97+
try
9798
{
98-
__content_422 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false);
99-
__value_422 = global::G.HTTPValidationError.FromJson(__content_422, JsonSerializerOptions);
99+
if (ReadResponseAsString)
100+
{
101+
__content_422 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false);
102+
__value_422 = global::G.HTTPValidationError.FromJson(__content_422, JsonSerializerOptions);
103+
}
104+
else
105+
{
106+
var __contentStream_422 = await __response.Content.ReadAsStreamAsync(cancellationToken).ConfigureAwait(false);
107+
__value_422 = await global::G.HTTPValidationError.FromJsonStreamAsync(__contentStream_422, JsonSerializerOptions).ConfigureAwait(false);
108+
}
100109
}
101-
else
110+
catch (global::System.Exception __ex)
102111
{
103-
var __contentStream_422 = await __response.Content.ReadAsStreamAsync(cancellationToken).ConfigureAwait(false);
104-
__value_422 = await global::G.HTTPValidationError.FromJsonStreamAsync(__contentStream_422, JsonSerializerOptions).ConfigureAwait(false);
112+
__exception_422 = __ex;
105113
}
106114

107115
throw new global::G.ApiException<global::G.HTTPValidationError>(
108116
message: __content_422 ?? __response.ReasonPhrase ?? string.Empty,
117+
innerException: __exception_422,
109118
statusCode: __response.StatusCode)
110119
{
111120
ResponseBody = __content_422,

0 commit comments

Comments
 (0)