Skip to content

Commit 700cdb8

Browse files
committed
Merge branch 'hotfix/improve-response-capture-semantics'
2 parents e7c6cc9 + b29d613 commit 700cdb8

File tree

1 file changed

+18
-3
lines changed

1 file changed

+18
-3
lines changed

libs/TrybeSDK/ApiClient.cs

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -348,9 +348,24 @@ protected internal (HttpRequestMessage, string?) CreateHttpRequest<TRequest>(
348348
Meta? meta = default;
349349
if (content is not null || stringContent is { Length: >0 })
350350
{
351-
data = stringContent is { Length: > 0 }
352-
? JsonSerializer.Deserialize<DataContainer<TResponse>>(stringContent, _deserializerOptions)
353-
: await JsonSerializer.DeserializeAsync<DataContainer<TResponse>>(content!, _deserializerOptions).ConfigureAwait(false);
351+
try
352+
{
353+
data = stringContent is { Length: > 0 }
354+
? JsonSerializer.Deserialize<DataContainer<TResponse>>(stringContent, _deserializerOptions)
355+
: await JsonSerializer.DeserializeAsync<DataContainer<TResponse>>(content!, _deserializerOptions).ConfigureAwait(false);
356+
}
357+
catch (Exception ex)
358+
{
359+
return new(
360+
new TrybeResponse<TResponse>(
361+
method,
362+
uri,
363+
response.IsSuccessStatusCode,
364+
response.StatusCode,
365+
rateLimiting: rateLimiting,
366+
error: new Error(ex.Message, exception: ex)
367+
), stringContent);
368+
}
354369

355370
if (data?.Meta is not null)
356371
{

0 commit comments

Comments
 (0)