diff --git a/ClickHouse.Client/ADO/ClickHouseConnection.cs b/ClickHouse.Client/ADO/ClickHouseConnection.cs index a8dea22..cae1bc6 100644 --- a/ClickHouse.Client/ADO/ClickHouseConnection.cs +++ b/ClickHouse.Client/ADO/ClickHouseConnection.cs @@ -218,15 +218,16 @@ internal static async Task HandleError(HttpResponseMessage activity.SetSuccess(); return response; } - activity.SetStatus(ActivityStatusCode.Error, response?.ReasonPhrase ?? string.Empty); - var ex = new Exception($"Error '{response.StatusCode}' reading server response: {response.ReasonPhrase}"); + string description = response?.ReasonPhrase ?? string.Empty; + activity?.SetStatus(ActivityStatusCode.Error, description); + var ex = new Exception($"Error '{response?.StatusCode}' reading server response: {description}"); try { await response.Content.LoadIntoBufferAsync(4096); var stream = (MemoryStream)await response.Content.ReadAsStreamAsync(); var error = new StreamReader(stream).ReadToEnd(); ex = ClickHouseServerException.FromServerResponse(error, query); - activity.SetException(ex); + activity?.SetException(ex); } finally {