Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 33 additions & 12 deletions EosSharp/EosSharp/HttpHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -223,31 +223,52 @@ public async Task<Stream> 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<ApiErrorException>(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<ApiErrorException>(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;
}

/// <summary>
Expand Down