diff --git a/ClickHouse.Client/ADO/ClickHouseConnection.cs b/ClickHouse.Client/ADO/ClickHouseConnection.cs index 40f0d221..cae1bc67 100644 --- a/ClickHouse.Client/ADO/ClickHouseConnection.cs +++ b/ClickHouse.Client/ADO/ClickHouseConnection.cs @@ -218,10 +218,21 @@ internal static async Task HandleError(HttpResponseMessage activity.SetSuccess(); return response; } - var error = await response.Content.ReadAsStringAsync().ConfigureAwait(false); - var ex = ClickHouseServerException.FromServerResponse(error, query); - activity.SetException(ex); - throw ex; + 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); + } + finally + { + throw ex; + } } public override void ChangeDatabase(string databaseName) => database = databaseName;