Skip to content

Commit 2146571

Browse files
committed
feat(debug): Now JSON deserialization exceptions will be more clear.
1 parent 63f959b commit 2146571

File tree

5,693 files changed

+83059
-83059
lines changed

Some content is hidden

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

5,693 files changed

+83059
-83059
lines changed

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

Lines changed: 35 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -434,8 +434,16 @@ public static string GenerateResponse(
434434
try
435435
{{
436436
__response.EnsureSuccessStatusCode();
437+
438+
{(string.IsNullOrWhiteSpace(endPoint.SuccessResponse.Type.CSharpType)
439+
? " "
440+
: endPoint is { ContentType: ContentType.String, SuccessResponse.Type.CSharpTypeWithoutNullability: not "string" } ? $@"
441+
return
442+
{jsonSerializer.GenerateDeserializeCall("__content", endPoint.SuccessResponse.Type, endPoint.Settings.JsonSerializerContext)} ??
443+
throw new global::System.InvalidOperationException($""Response deserialization failed for \""{{__content}}\"" "");" : @"
444+
return __content;")}
437445
}}
438-
catch (global::System.Net.Http.HttpRequestException __ex)
446+
catch (global::System.Exception __ex)
439447
{{
440448
throw new global::{endPoint.GlobalSettings.Namespace}.ApiException(
441449
{(endPoint.ContentType == ContentType.String ? $@"
@@ -452,22 +460,39 @@ public static string GenerateResponse(
452460
h => h.Value),
453461
}};
454462
}}
455-
456-
{(string.IsNullOrWhiteSpace(endPoint.SuccessResponse.Type.CSharpType)
457-
? " "
458-
: endPoint is { ContentType: ContentType.String, SuccessResponse.Type.CSharpTypeWithoutNullability: not "string" } ? $@"
459-
return
460-
{jsonSerializer.GenerateDeserializeCall("__content", endPoint.SuccessResponse.Type, endPoint.Settings.JsonSerializerContext)} ??
461-
throw new global::System.InvalidOperationException($""Response deserialization failed for \""{{__content}}\"" "");" : @"
462-
return __content;")}
463463
}}
464464
else
465465
{{
466466
try
467467
{{
468468
__response.EnsureSuccessStatusCode();
469+
470+
{endPoint.ContentType switch
471+
{
472+
ContentType.String when endPoint.SuccessResponse.Type.CSharpTypeWithoutNullability is not "string" => "using ",
473+
ContentType.Stream => "using ",
474+
_ => string.Empty,
475+
}}var __content = await __response.Content.ReadAs{endPoint.ContentType switch
476+
{
477+
ContentType.String when endPoint.SuccessResponse.Type.CSharpTypeWithoutNullability is "string" => "String",
478+
ContentType.String => "Stream",
479+
ContentType.Stream => "Stream",
480+
_ => "ByteArray",
481+
}}Async(
482+
#if NET5_0_OR_GREATER
483+
cancellationToken
484+
#endif
485+
).ConfigureAwait(false);
486+
487+
{(string.IsNullOrWhiteSpace(endPoint.SuccessResponse.Type.CSharpType)
488+
? " "
489+
: endPoint is { ContentType: ContentType.String, SuccessResponse.Type.CSharpTypeWithoutNullability: not "string" } ? $@"
490+
return
491+
{jsonSerializer.GenerateDeserializeFromStreamCall("__content", endPoint.SuccessResponse.Type, endPoint.Settings.JsonSerializerContext)} ??
492+
throw new global::System.InvalidOperationException(""Response deserialization failed."");" : @"
493+
return __content;")}
469494
}}
470-
catch (global::System.Net.Http.HttpRequestException __ex)
495+
catch (global::System.Exception __ex)
471496
{{
472497
throw new global::{endPoint.GlobalSettings.Namespace}.ApiException(
473498
message: __response.ReasonPhrase ?? string.Empty,
@@ -480,31 +505,6 @@ public static string GenerateResponse(
480505
h => h.Value),
481506
}};
482507
}}
483-
484-
{endPoint.ContentType switch
485-
{
486-
ContentType.String when endPoint.SuccessResponse.Type.CSharpTypeWithoutNullability is not "string" => "using ",
487-
ContentType.Stream => "using ",
488-
_ => string.Empty,
489-
}}var __content = await __response.Content.ReadAs{endPoint.ContentType switch
490-
{
491-
ContentType.String when endPoint.SuccessResponse.Type.CSharpTypeWithoutNullability is "string" => "String",
492-
ContentType.String => "Stream",
493-
ContentType.Stream => "Stream",
494-
_ => "ByteArray",
495-
}}Async(
496-
#if NET5_0_OR_GREATER
497-
cancellationToken
498-
#endif
499-
).ConfigureAwait(false);
500-
501-
{(string.IsNullOrWhiteSpace(endPoint.SuccessResponse.Type.CSharpType)
502-
? " "
503-
: endPoint is { ContentType: ContentType.String, SuccessResponse.Type.CSharpTypeWithoutNullability: not "string" } ? $@"
504-
return
505-
{jsonSerializer.GenerateDeserializeFromStreamCall("__content", endPoint.SuccessResponse.Type, endPoint.Settings.JsonSerializerContext)} ??
506-
throw new global::System.InvalidOperationException(""Response deserialization failed."");" : @"
507-
return __content;")}
508508
}}
509509
";
510510
}

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

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -142,8 +142,10 @@ partial void ProcessConvertDocumentFileStudioV1ChatFilesConvertPostResponseConte
142142
try
143143
{
144144
__response.EnsureSuccessStatusCode();
145+
146+
return __content;
145147
}
146-
catch (global::System.Net.Http.HttpRequestException __ex)
148+
catch (global::System.Exception __ex)
147149
{
148150
throw new global::G.ApiException(
149151
message: __content ?? __response.ReasonPhrase ?? string.Empty,
@@ -157,16 +159,22 @@ partial void ProcessConvertDocumentFileStudioV1ChatFilesConvertPostResponseConte
157159
h => h.Value),
158160
};
159161
}
160-
161-
return __content;
162162
}
163163
else
164164
{
165165
try
166166
{
167167
__response.EnsureSuccessStatusCode();
168+
169+
var __content = await __response.Content.ReadAsStringAsync(
170+
#if NET5_0_OR_GREATER
171+
cancellationToken
172+
#endif
173+
).ConfigureAwait(false);
174+
175+
return __content;
168176
}
169-
catch (global::System.Net.Http.HttpRequestException __ex)
177+
catch (global::System.Exception __ex)
170178
{
171179
throw new global::G.ApiException(
172180
message: __response.ReasonPhrase ?? string.Empty,
@@ -179,14 +187,6 @@ partial void ProcessConvertDocumentFileStudioV1ChatFilesConvertPostResponseConte
179187
h => h.Value),
180188
};
181189
}
182-
183-
var __content = await __response.Content.ReadAsStringAsync(
184-
#if NET5_0_OR_GREATER
185-
cancellationToken
186-
#endif
187-
).ConfigureAwait(false);
188-
189-
return __content;
190190
}
191191
}
192192

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

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -129,8 +129,12 @@ partial void ProcessGenerateOrgTokenStudioV1ConnectorsConnectedUsersOrganization
129129
try
130130
{
131131
__response.EnsureSuccessStatusCode();
132+
133+
return
134+
global::G.ConnectorsToken.FromJson(__content, JsonSerializerOptions) ??
135+
throw new global::System.InvalidOperationException($"Response deserialization failed for \"{__content}\" ");
132136
}
133-
catch (global::System.Net.Http.HttpRequestException __ex)
137+
catch (global::System.Exception __ex)
134138
{
135139
throw new global::G.ApiException(
136140
message: __content ?? __response.ReasonPhrase ?? string.Empty,
@@ -144,18 +148,24 @@ partial void ProcessGenerateOrgTokenStudioV1ConnectorsConnectedUsersOrganization
144148
h => h.Value),
145149
};
146150
}
147-
148-
return
149-
global::G.ConnectorsToken.FromJson(__content, JsonSerializerOptions) ??
150-
throw new global::System.InvalidOperationException($"Response deserialization failed for \"{__content}\" ");
151151
}
152152
else
153153
{
154154
try
155155
{
156156
__response.EnsureSuccessStatusCode();
157+
158+
using var __content = await __response.Content.ReadAsStreamAsync(
159+
#if NET5_0_OR_GREATER
160+
cancellationToken
161+
#endif
162+
).ConfigureAwait(false);
163+
164+
return
165+
await global::G.ConnectorsToken.FromJsonStreamAsync(__content, JsonSerializerOptions).ConfigureAwait(false) ??
166+
throw new global::System.InvalidOperationException("Response deserialization failed.");
157167
}
158-
catch (global::System.Net.Http.HttpRequestException __ex)
168+
catch (global::System.Exception __ex)
159169
{
160170
throw new global::G.ApiException(
161171
message: __response.ReasonPhrase ?? string.Empty,
@@ -168,16 +178,6 @@ partial void ProcessGenerateOrgTokenStudioV1ConnectorsConnectedUsersOrganization
168178
h => h.Value),
169179
};
170180
}
171-
172-
using var __content = await __response.Content.ReadAsStreamAsync(
173-
#if NET5_0_OR_GREATER
174-
cancellationToken
175-
#endif
176-
).ConfigureAwait(false);
177-
178-
return
179-
await global::G.ConnectorsToken.FromJsonStreamAsync(__content, JsonSerializerOptions).ConfigureAwait(false) ??
180-
throw new global::System.InvalidOperationException("Response deserialization failed.");
181181
}
182182
}
183183
}

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

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -135,8 +135,12 @@ partial void ProcessGetDataSourceStatusStudioV1ConnectorsConnectedUsersOrganizat
135135
try
136136
{
137137
__response.EnsureSuccessStatusCode();
138+
139+
return
140+
global::G.ConnectorsStatus.FromJson(__content, JsonSerializerOptions) ??
141+
throw new global::System.InvalidOperationException($"Response deserialization failed for \"{__content}\" ");
138142
}
139-
catch (global::System.Net.Http.HttpRequestException __ex)
143+
catch (global::System.Exception __ex)
140144
{
141145
throw new global::G.ApiException(
142146
message: __content ?? __response.ReasonPhrase ?? string.Empty,
@@ -150,18 +154,24 @@ partial void ProcessGetDataSourceStatusStudioV1ConnectorsConnectedUsersOrganizat
150154
h => h.Value),
151155
};
152156
}
153-
154-
return
155-
global::G.ConnectorsStatus.FromJson(__content, JsonSerializerOptions) ??
156-
throw new global::System.InvalidOperationException($"Response deserialization failed for \"{__content}\" ");
157157
}
158158
else
159159
{
160160
try
161161
{
162162
__response.EnsureSuccessStatusCode();
163+
164+
using var __content = await __response.Content.ReadAsStreamAsync(
165+
#if NET5_0_OR_GREATER
166+
cancellationToken
167+
#endif
168+
).ConfigureAwait(false);
169+
170+
return
171+
await global::G.ConnectorsStatus.FromJsonStreamAsync(__content, JsonSerializerOptions).ConfigureAwait(false) ??
172+
throw new global::System.InvalidOperationException("Response deserialization failed.");
163173
}
164-
catch (global::System.Net.Http.HttpRequestException __ex)
174+
catch (global::System.Exception __ex)
165175
{
166176
throw new global::G.ApiException(
167177
message: __response.ReasonPhrase ?? string.Empty,
@@ -174,16 +184,6 @@ partial void ProcessGetDataSourceStatusStudioV1ConnectorsConnectedUsersOrganizat
174184
h => h.Value),
175185
};
176186
}
177-
178-
using var __content = await __response.Content.ReadAsStreamAsync(
179-
#if NET5_0_OR_GREATER
180-
cancellationToken
181-
#endif
182-
).ConfigureAwait(false);
183-
184-
return
185-
await global::G.ConnectorsStatus.FromJsonStreamAsync(__content, JsonSerializerOptions).ConfigureAwait(false) ??
186-
throw new global::System.InvalidOperationException("Response deserialization failed.");
187187
}
188188
}
189189
}

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

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -129,8 +129,12 @@ partial void ProcessGetOrgDataSourcesInfoStudioV1ConnectorsConnectedUsersOrganiz
129129
try
130130
{
131131
__response.EnsureSuccessStatusCode();
132+
133+
return
134+
global::G.ConnectorsDataSources.FromJson(__content, JsonSerializerOptions) ??
135+
throw new global::System.InvalidOperationException($"Response deserialization failed for \"{__content}\" ");
132136
}
133-
catch (global::System.Net.Http.HttpRequestException __ex)
137+
catch (global::System.Exception __ex)
134138
{
135139
throw new global::G.ApiException(
136140
message: __content ?? __response.ReasonPhrase ?? string.Empty,
@@ -144,18 +148,24 @@ partial void ProcessGetOrgDataSourcesInfoStudioV1ConnectorsConnectedUsersOrganiz
144148
h => h.Value),
145149
};
146150
}
147-
148-
return
149-
global::G.ConnectorsDataSources.FromJson(__content, JsonSerializerOptions) ??
150-
throw new global::System.InvalidOperationException($"Response deserialization failed for \"{__content}\" ");
151151
}
152152
else
153153
{
154154
try
155155
{
156156
__response.EnsureSuccessStatusCode();
157+
158+
using var __content = await __response.Content.ReadAsStreamAsync(
159+
#if NET5_0_OR_GREATER
160+
cancellationToken
161+
#endif
162+
).ConfigureAwait(false);
163+
164+
return
165+
await global::G.ConnectorsDataSources.FromJsonStreamAsync(__content, JsonSerializerOptions).ConfigureAwait(false) ??
166+
throw new global::System.InvalidOperationException("Response deserialization failed.");
157167
}
158-
catch (global::System.Net.Http.HttpRequestException __ex)
168+
catch (global::System.Exception __ex)
159169
{
160170
throw new global::G.ApiException(
161171
message: __response.ReasonPhrase ?? string.Empty,
@@ -168,16 +178,6 @@ partial void ProcessGetOrgDataSourcesInfoStudioV1ConnectorsConnectedUsersOrganiz
168178
h => h.Value),
169179
};
170180
}
171-
172-
using var __content = await __response.Content.ReadAsStreamAsync(
173-
#if NET5_0_OR_GREATER
174-
cancellationToken
175-
#endif
176-
).ConfigureAwait(false);
177-
178-
return
179-
await global::G.ConnectorsDataSources.FromJsonStreamAsync(__content, JsonSerializerOptions).ConfigureAwait(false) ??
180-
throw new global::System.InvalidOperationException("Response deserialization failed.");
181181
}
182182
}
183183
}

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

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -137,8 +137,12 @@ partial void ProcessV1ConversationalRagResponseContent(
137137
try
138138
{
139139
__response.EnsureSuccessStatusCode();
140+
141+
return
142+
global::G.ConversationalRagResult.FromJson(__content, JsonSerializerOptions) ??
143+
throw new global::System.InvalidOperationException($"Response deserialization failed for \"{__content}\" ");
140144
}
141-
catch (global::System.Net.Http.HttpRequestException __ex)
145+
catch (global::System.Exception __ex)
142146
{
143147
throw new global::G.ApiException(
144148
message: __content ?? __response.ReasonPhrase ?? string.Empty,
@@ -152,18 +156,24 @@ partial void ProcessV1ConversationalRagResponseContent(
152156
h => h.Value),
153157
};
154158
}
155-
156-
return
157-
global::G.ConversationalRagResult.FromJson(__content, JsonSerializerOptions) ??
158-
throw new global::System.InvalidOperationException($"Response deserialization failed for \"{__content}\" ");
159159
}
160160
else
161161
{
162162
try
163163
{
164164
__response.EnsureSuccessStatusCode();
165+
166+
using var __content = await __response.Content.ReadAsStreamAsync(
167+
#if NET5_0_OR_GREATER
168+
cancellationToken
169+
#endif
170+
).ConfigureAwait(false);
171+
172+
return
173+
await global::G.ConversationalRagResult.FromJsonStreamAsync(__content, JsonSerializerOptions).ConfigureAwait(false) ??
174+
throw new global::System.InvalidOperationException("Response deserialization failed.");
165175
}
166-
catch (global::System.Net.Http.HttpRequestException __ex)
176+
catch (global::System.Exception __ex)
167177
{
168178
throw new global::G.ApiException(
169179
message: __response.ReasonPhrase ?? string.Empty,
@@ -176,16 +186,6 @@ partial void ProcessV1ConversationalRagResponseContent(
176186
h => h.Value),
177187
};
178188
}
179-
180-
using var __content = await __response.Content.ReadAsStreamAsync(
181-
#if NET5_0_OR_GREATER
182-
cancellationToken
183-
#endif
184-
).ConfigureAwait(false);
185-
186-
return
187-
await global::G.ConversationalRagResult.FromJsonStreamAsync(__content, JsonSerializerOptions).ConfigureAwait(false) ??
188-
throw new global::System.InvalidOperationException("Response deserialization failed.");
189189
}
190190
}
191191

0 commit comments

Comments
 (0)