Skip to content

Commit 515d738

Browse files
committed
fix: errors on e.g. parse result did not get added to trace
1 parent 8609484 commit 515d738

File tree

1 file changed

+28
-6
lines changed

1 file changed

+28
-6
lines changed

Catglobe.CgScript.Runtime/ApiClientBase.cs

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,23 @@ private async Task<ScriptResult<TR>> ParseResponse<TR>(HttpResponseMessage call,
3838
logger.LogInformation(await call.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false));
3939
call.EnsureSuccessStatusCode();
4040
}
41-
var result = await call.Content.ReadFromJsonAsync(jsonTypeInfo, cancellationToken).ConfigureAwait(false);
42-
if (result?.Error is not null)
41+
try
42+
{
43+
var result = await call.Content.ReadFromJsonAsync(jsonTypeInfo, cancellationToken).ConfigureAwait(false);
44+
if (result?.Error is not null)
45+
{
46+
Activity.Current?.SetStatus(ActivityStatusCode.Error);
47+
}
48+
return result ?? throw new IOException("Could not deserialize result");
49+
} catch (OperationCanceledException e)
50+
{
51+
throw;
52+
} catch (Exception e)
4353
{
4454
Activity.Current?.SetStatus(ActivityStatusCode.Error);
55+
Activity.Current?.AddException(e);
56+
throw;
4557
}
46-
return result ?? throw new IOException("Could not deserialize result");
4758
}
4859

4960
[RequiresUnreferencedCode("JSON")]
@@ -85,12 +96,23 @@ private async Task<ScriptResult<TR>> ParseResponse<TR>(HttpResponseMessage call,
8596
logger.LogInformation(await call.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false));
8697
call.EnsureSuccessStatusCode();
8798
}
88-
var result = (ScriptResult<TR>?)await call.Content.ReadFromJsonAsync(typeof(ScriptResult<TR>), retOptions, cancellationToken).ConfigureAwait(false);
89-
if (result?.Error is not null)
99+
try
100+
{
101+
var result = (ScriptResult<TR>?)await call.Content.ReadFromJsonAsync(typeof(ScriptResult<TR>), retOptions, cancellationToken).ConfigureAwait(false);
102+
if (result?.Error is not null)
103+
{
104+
Activity.Current?.SetStatus(ActivityStatusCode.Error);
105+
}
106+
return result ?? throw new IOException("Could not deserialize result");
107+
} catch (OperationCanceledException e)
108+
{
109+
throw;
110+
} catch (Exception e)
90111
{
91112
Activity.Current?.SetStatus(ActivityStatusCode.Error);
113+
Activity.Current?.AddException(e);
114+
throw;
92115
}
93-
return result ?? throw new IOException("Could not deserialize result");
94116
}
95117

96118
protected abstract ValueTask<string> GetPath(string scriptName, string? additionalParameters = null);

0 commit comments

Comments
 (0)