From 00848de18a392622edbb5ff948e1be699b17e688 Mon Sep 17 00:00:00 2001 From: Artur Pietrzyk Date: Wed, 24 Apr 2024 01:17:44 +0200 Subject: [PATCH] Update CoinApiRestClient.cs --- .../csharp-rest/CoinAPI.REST.V1/CoinApiRestClient.cs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/data-api/csharp-rest/CoinAPI.REST.V1/CoinApiRestClient.cs b/data-api/csharp-rest/CoinAPI.REST.V1/CoinApiRestClient.cs index 4da5d9063..dd5bafa30 100644 --- a/data-api/csharp-rest/CoinAPI.REST.V1/CoinApiRestClient.cs +++ b/data-api/csharp-rest/CoinAPI.REST.V1/CoinApiRestClient.cs @@ -60,7 +60,8 @@ private async Task GetData(string url) private static async Task RaiseError(HttpResponseMessage response) { - var message = (await Deserialize(response).ConfigureAwait(false)).message; + var responseString = await responseMessage.Content.ReadAsStringAsync().ConfigureAwait(false); + var message = (await DeserializeFromString(responseString).ConfigureAwait(false))?.message ?? responseString; switch ((int)response.StatusCode) { @@ -79,6 +80,12 @@ private static async Task RaiseError(HttpResponseMessage response) } } + private static async Task DeserializeFromString(string responseString) + { + var data = JsonConvert.DeserializeObject(responseString); + return data; + } + private static async Task Deserialize(HttpResponseMessage responseMessage) { var responseString = await responseMessage.Content.ReadAsStringAsync().ConfigureAwait(false);