Skip to content

Commit

Permalink
Less Nesting
Browse files Browse the repository at this point in the history
  • Loading branch information
ajrice6713 committed Nov 14, 2024
1 parent 615558a commit 70829c6
Showing 1 changed file with 30 additions and 33 deletions.
63 changes: 30 additions & 33 deletions Bandwidth.Iris/Client.cs
Original file line number Diff line number Diff line change
Expand Up @@ -397,50 +397,47 @@ private static string FixPath(string path)

private async Task CheckResponse(HttpResponseMessage response)
{
if (!response.IsSuccessStatusCode)
if (response.IsSuccessStatusCode) return;
try
{
try
var xml = await response.Content.ReadAsStringAsync();
if (xml.Length > 0)
{
var xml = await response.Content.ReadAsStringAsync();
if (xml.Length > 0)
var doc = XDocument.Parse(xml);
var code = doc.Descendants("ErrorCode").FirstOrDefault();
var description = doc.Descendants("Description").FirstOrDefault();
if (code == null)
{
var doc = XDocument.Parse(xml);
var code = doc.Descendants("ErrorCode").FirstOrDefault();
var description = doc.Descendants("Description").FirstOrDefault();
if (code == null)
var error = doc.Descendants("Error").FirstOrDefault();
if (error == null)
{
var error = doc.Descendants("Error").FirstOrDefault();
if (error == null)
{
var exceptions =
(from item in doc.Descendants("Errors")
select
(Exception)new BandwidthIrisException(item.Element("Code").Value,
item.Element("Description").Value, response.StatusCode)).ToArray();
if (exceptions.Length > 0)
{
throw new AggregateException(exceptions);
}
code = doc.Descendants("resultCode").FirstOrDefault();
description = doc.Descendants("resultMessage").FirstOrDefault();
}
else
var exceptions =
(from item in doc.Descendants("Errors")
select
(Exception)new BandwidthIrisException(item.Element("Code").Value,
item.Element("Description").Value, response.StatusCode)).ToArray();
if (exceptions.Length > 0)
{
code = error.Element("Code");
description = error.Element("Description");
throw new AggregateException(exceptions);
}
code = doc.Descendants("resultCode").FirstOrDefault();
description = doc.Descendants("resultMessage").FirstOrDefault();
}
if (code != null && description != null && !string.IsNullOrEmpty(code.Value) && code.Value != "0")
else
{
throw new BandwidthIrisException(code.Value, description.Value, response.StatusCode, doc);
code = error.Element("Code");
description = error.Element("Description");
}
}
if (code != null && description != null && !string.IsNullOrEmpty(code.Value) && code.Value != "0")
{
throw new BandwidthIrisException(code.Value, description.Value, response.StatusCode, doc);
}
}
catch (Exception ex) when (!(ex is BandwidthIrisException) && !(ex is AggregateException))
{

throw new BandwidthIrisException("", string.Format("Http code {0}", response.StatusCode), response.StatusCode);
}
}
catch (Exception ex) when (!(ex is BandwidthIrisException) && !(ex is AggregateException))
{
throw new BandwidthIrisException("", string.Format("Http code {0}", response.StatusCode), response.StatusCode);
}
}

Expand Down

0 comments on commit 70829c6

Please sign in to comment.