mirror of
https://github.com/Ombi-app/Ombi.git
synced 2025-07-11 15:56:05 -07:00
stop throwing new exceptions instead of just rethrow
This commit is contained in:
parent
24bb0207d5
commit
4baff16d07
1 changed files with 45 additions and 59 deletions
|
@ -6,46 +6,39 @@ namespace Ombi.Helpers
|
||||||
{
|
{
|
||||||
private const string Https = "Https";
|
private const string Https = "Https";
|
||||||
private const string Http = "Http";
|
private const string Http = "Http";
|
||||||
|
|
||||||
public static Uri ReturnUri(this string val)
|
public static Uri ReturnUri(this string val)
|
||||||
{
|
{
|
||||||
if (val == null)
|
if (val == null)
|
||||||
{
|
{
|
||||||
throw new ApplicationSettingsException("The URI is null, please check your settings to make sure you have configured the applications correctly.");
|
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 uri = new UriBuilder();
|
uri = new UriBuilder(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);
|
|
||||||
|
|
||||||
uri = split.Length == 3
|
|
||||||
? new UriBuilder(Http, split[0], port, "/" + split[2])
|
|
||||||
: new UriBuilder(Http, split[0], port);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
uri = new UriBuilder(Http, val);
|
|
||||||
}
|
|
||||||
|
|
||||||
return uri.Uri;
|
|
||||||
}
|
}
|
||||||
catch (Exception exception)
|
else if (val.StartsWith("https://", StringComparison.Ordinal))
|
||||||
{
|
{
|
||||||
throw new Exception(exception.Message, exception);
|
uri = new UriBuilder(val);
|
||||||
}
|
}
|
||||||
|
else if (val.Contains(":"))
|
||||||
|
{
|
||||||
|
var split = val.Split(':', '/');
|
||||||
|
int port;
|
||||||
|
int.TryParse(split[1], out port);
|
||||||
|
|
||||||
|
uri = split.Length == 3
|
||||||
|
? new UriBuilder(Http, split[0], port, "/" + split[2])
|
||||||
|
: new UriBuilder(Http, split[0], port);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
uri = new UriBuilder(Http, val);
|
||||||
|
}
|
||||||
|
|
||||||
|
return uri.Uri;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <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.");
|
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();
|
||||||
{
|
|
||||||
var uri = new UriBuilder();
|
|
||||||
|
|
||||||
if (val.StartsWith("http://", StringComparison.Ordinal))
|
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);
|
|
||||||
}
|
|
||||||
|
|
||||||
return uri.Uri;
|
|
||||||
}
|
|
||||||
catch (Exception exception)
|
|
||||||
{
|
{
|
||||||
throw new Exception(exception.Message, exception);
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
return uri.Uri;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Uri ReturnUriWithSubDir(this string val, int port, bool ssl, string subDir)
|
public static Uri ReturnUriWithSubDir(this string val, int port, bool ssl, string subDir)
|
||||||
|
@ -112,7 +98,7 @@ namespace Ombi.Helpers
|
||||||
|
|
||||||
return uriBuilder.Uri;
|
return uriBuilder.Uri;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public class ApplicationSettingsException : Exception
|
public class ApplicationSettingsException : Exception
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue