stop throwing new exceptions instead of just rethrow

pull/3895/head
Jamie Rees 6 years ago
parent 24bb0207d5
commit 4baff16d07

@ -6,46 +6,39 @@ namespace Ombi.Helpers
{
private const string Https = "Https";
private const string Http = "Http";
public static Uri ReturnUri(this string val)
{
if (val == null)
{
throw new ApplicationSettingsException("The URI is null, please check your settings to make sure you have configured the applications correctly.");
}
try
{
var uri = new UriBuilder();
if (val.StartsWith("http://", StringComparison.Ordinal))
{
uri = new UriBuilder(val);
}
else if (val.StartsWith("https://", StringComparison.Ordinal))
{
uri = new UriBuilder(val);
}
else if (val.Contains(":"))
{
var split = val.Split(':', '/');
int port;
int.TryParse(split[1], out port);
var uri = new UriBuilder();
uri = split.Length == 3
? new UriBuilder(Http, split[0], port, "/" + split[2])
: new UriBuilder(Http, split[0], port);
}
else
{
uri = new UriBuilder(Http, val);
}
if (val.StartsWith("http://", StringComparison.Ordinal))
{
uri = new UriBuilder(val);
}
else if (val.StartsWith("https://", StringComparison.Ordinal))
{
uri = new UriBuilder(val);
}
else if (val.Contains(":"))
{
var split = val.Split(':', '/');
int port;
int.TryParse(split[1], out port);
return uri.Uri;
uri = split.Length == 3
? new UriBuilder(Http, split[0], port, "/" + split[2])
: new UriBuilder(Http, split[0], port);
}
catch (Exception exception)
else
{
throw new Exception(exception.Message, exception);
uri = new UriBuilder(Http, val);
}
return uri.Uri;
}
/// <summary>
@ -64,37 +57,30 @@ namespace Ombi.Helpers
{
throw new ApplicationSettingsException("The URI is null, please check your settings to make sure you have configured the applications correctly.");
}
try
{
var uri = new UriBuilder();
if (val.StartsWith("http://", StringComparison.Ordinal))
{
var split = val.Split('/');
uri = split.Length >= 4 ? new UriBuilder(Http, split[2], port, "/" + split[3]) : new UriBuilder(new Uri($"{val}:{port}"));
}
else if (val.StartsWith("https://", StringComparison.Ordinal))
{
var split = val.Split('/');
uri = split.Length >= 4
? new UriBuilder(Https, split[2], port, "/" + split[3])
: new UriBuilder(Https, split[2], port);
}
else if (ssl)
{
uri = new UriBuilder(Https, val, port);
}
else
{
uri = new UriBuilder(Http, val, port);
}
var uri = new UriBuilder();
return uri.Uri;
if (val.StartsWith("http://", StringComparison.Ordinal))
{
var split = val.Split('/');
uri = split.Length >= 4 ? new UriBuilder(Http, split[2], port, "/" + split[3]) : new UriBuilder(new Uri($"{val}:{port}"));
}
else if (val.StartsWith("https://", StringComparison.Ordinal))
{
var split = val.Split('/');
uri = split.Length >= 4
? new UriBuilder(Https, split[2], port, "/" + split[3])
: new UriBuilder(Https, split[2], port);
}
catch (Exception exception)
else if (ssl)
{
throw new Exception(exception.Message, exception);
uri = new UriBuilder(Https, val, port);
}
else
{
uri = new UriBuilder(Http, val, port);
}
return uri.Uri;
}
public static Uri ReturnUriWithSubDir(this string val, int port, bool ssl, string subDir)
@ -112,7 +98,7 @@ namespace Ombi.Helpers
return uriBuilder.Uri;
}
}
public class ApplicationSettingsException : Exception

Loading…
Cancel
Save