diff --git a/EosSharp/EosSharp/HttpHelper.cs b/EosSharp/EosSharp/HttpHelper.cs index 092e754..6d04e9f 100644 --- a/EosSharp/EosSharp/HttpHelper.cs +++ b/EosSharp/EosSharp/HttpHelper.cs @@ -223,31 +223,52 @@ public async Task BuildSendResponse(HttpResponseMessage response) var stream = await response.Content.ReadAsStreamAsync(); if (response.IsSuccessStatusCode) return stream; - var content = await StreamToStringAsync(stream); - if(string.IsNullOrEmpty(content)) + string content = null; + try { - throw new NullReferenceException($"Couldn't parse stream data. Content: {content}, Status code: {response.StatusCode}"); + content = await StreamToStringAsync(stream); } - - ApiErrorException apiError = null; - try + catch (System.Exception ex) { - apiError = JsonConvert.DeserializeObject(content); + throw new ApiException + { + StatusCode = (int)response.StatusCode, + Content = $"Couldn't parse stream data. exception: {ex.ToString()}" + }; } - catch(Exception) + + if(string.IsNullOrEmpty(content)) { throw new ApiException { StatusCode = (int)response.StatusCode, - Content = content + Content = $"Couldn't parse stream data." }; } - if(apiError == null) + try + { + ApiErrorException apiError = JsonConvert.DeserializeObject(content); + + if(apiError == null) + { + throw new ApiException + { + StatusCode = (int)response.StatusCode, + Content = $"Api error is null! Status code: {response.StatusCode}, content: {content}" + }; + } + + throw apiError; + } + catch(Exception ex) { - throw new NullReferenceException($"Api error is null! Response was: {content}"); + throw new ApiException + { + StatusCode = (int)response.StatusCode, + Content = $"Couldn't deserialized api error, exception: {ex.ToString()}, content: {content}" + }; } - throw apiError; } ///