From 387f8df0ff5be47765c9e44df1f2cad8e05bf633 Mon Sep 17 00:00:00 2001 From: Qstick Date: Sat, 27 Nov 2021 21:07:42 -0600 Subject: [PATCH] Rework some Cardigann exception handling --- .../Definitions/Cardigann/CardigannParser.cs | 9 +++--- .../Cardigann/CardigannRequestGenerator.cs | 15 +++++---- .../CardigannConfigException.cs | 4 +-- .../Exceptions/CardigannException.cs | 32 +++++++++++++++++++ 4 files changed, 47 insertions(+), 13 deletions(-) rename src/NzbDrone.Core/Indexers/Definitions/Cardigann/{ => Exceptions}/CardigannConfigException.cs (82%) create mode 100644 src/NzbDrone.Core/Indexers/Definitions/Cardigann/Exceptions/CardigannException.cs diff --git a/src/NzbDrone.Core/Indexers/Definitions/Cardigann/CardigannParser.cs b/src/NzbDrone.Core/Indexers/Definitions/Cardigann/CardigannParser.cs index e97ff8b75..55ac4f3bd 100644 --- a/src/NzbDrone.Core/Indexers/Definitions/Cardigann/CardigannParser.cs +++ b/src/NzbDrone.Core/Indexers/Definitions/Cardigann/CardigannParser.cs @@ -10,6 +10,7 @@ using Newtonsoft.Json.Linq; using NLog; using NzbDrone.Common.Extensions; using NzbDrone.Core.Configuration; +using NzbDrone.Core.Indexers.Definitions.Cardigann.Exceptions; using NzbDrone.Core.Indexers.Exceptions; using NzbDrone.Core.Parser; using NzbDrone.Core.Parser.Model; @@ -67,7 +68,7 @@ namespace NzbDrone.Core.Indexers.Cardigann var parsedJson = JToken.Parse(results); if (parsedJson == null) { - throw new Exception("Error Parsing Json Response"); + throw new IndexerException(indexerResponse, "Error Parsing Json Response"); } if (search.Rows.Count != null) @@ -85,7 +86,7 @@ namespace NzbDrone.Core.Indexers.Cardigann var rowsObj = parsedJson.SelectToken(search.Rows.Selector); if (rowsObj == null) { - throw new Exception("Error Parsing Rows Selector"); + throw new IndexerException(indexerResponse, "Error Parsing Rows Selector"); } foreach (var row in rowsObj.Value()) @@ -140,7 +141,7 @@ namespace NzbDrone.Core.Indexers.Cardigann continue; } - throw new Exception(string.Format("Error while parsing field={0}, selector={1}, value={2}: {3}", field.Key, field.Value.Selector, value ?? "", ex.Message)); + throw new CardigannException(string.Format("Error while parsing field={0}, selector={1}, value={2}: {3}", field.Key, field.Value.Selector, value ?? "", ex.Message)); } var filters = search.Rows.Filters; @@ -327,7 +328,7 @@ namespace NzbDrone.Core.Indexers.Cardigann if (value == null && dateHeaders.Optional == false) { - throw new Exception(string.Format("No date header row found for {0}", release.ToString())); + throw new CardigannException(string.Format("No date header row found for {0}", release.ToString())); } if (value != null) diff --git a/src/NzbDrone.Core/Indexers/Definitions/Cardigann/CardigannRequestGenerator.cs b/src/NzbDrone.Core/Indexers/Definitions/Cardigann/CardigannRequestGenerator.cs index 6a369db40..052407c92 100644 --- a/src/NzbDrone.Core/Indexers/Definitions/Cardigann/CardigannRequestGenerator.cs +++ b/src/NzbDrone.Core/Indexers/Definitions/Cardigann/CardigannRequestGenerator.cs @@ -12,6 +12,7 @@ using NLog; using NzbDrone.Common.Http; using NzbDrone.Core.Configuration; using NzbDrone.Core.Indexers.Definitions.Cardigann; +using NzbDrone.Core.Indexers.Definitions.Cardigann.Exceptions; using NzbDrone.Core.IndexerSearch.Definitions; using NzbDrone.Core.Parser; using NzbDrone.Core.ThingiProvider; @@ -288,7 +289,7 @@ namespace NzbDrone.Core.Indexers.Cardigann } catch (Exception ex) { - throw new Exception(string.Format("Error while parsing selector input={0}, selector={1}, value={2}: {3}", selectorinput.Key, selectorinput.Value.Selector, value, ex.Message)); + throw new CardigannException(string.Format("Error while parsing selector input={0}, selector={1}, value={2}: {3}", selectorinput.Key, selectorinput.Value.Selector, value, ex.Message)); } } } @@ -306,7 +307,7 @@ namespace NzbDrone.Core.Indexers.Cardigann } catch (Exception ex) { - throw new Exception(string.Format("Error while parsing get selector input={0}, selector={1}, value={2}: {3}", selectorinput.Key, selectorinput.Value.Selector, value, ex.Message)); + throw new CardigannException(string.Format("Error while parsing get selector input={0}, selector={1}, value={2}: {3}", selectorinput.Key, selectorinput.Value.Selector, value, ex.Message)); } } } @@ -763,13 +764,13 @@ namespace NzbDrone.Core.Indexers.Cardigann var hash = MatchSelector(response, download.Infohash.Hash, variables); if (hash == null) { - throw new Exception($"InfoHash selectors didn't match"); + throw new CardigannException($"InfoHash selectors didn't match"); } var title = MatchSelector(response, download.Infohash.Title, variables); if (title == null) { - throw new Exception($"InfoHash selectors didn't match"); + throw new CardigannException($"InfoHash selectors didn't match"); } var magnet = MagnetLinkBuilder.BuildPublicMagnetLink(hash, title); @@ -846,7 +847,7 @@ namespace NzbDrone.Core.Indexers.Cardigann { _logger.Error("{0} CardigannIndexer ({1}): An exception occurred while trying selector {2}, retrying with next available selector", e, _definition.Id, queryselector); - throw new Exception(string.Format("An exception occurred while trying selector {0}", queryselector)); + throw new CardigannException(string.Format("An exception occurred while trying selector {0}", queryselector)); } } } @@ -888,7 +889,7 @@ namespace NzbDrone.Core.Indexers.Cardigann val = element.GetAttribute(selector.Attribute); if (val == null) { - throw new Exception($"Attribute \"{selector.Attribute}\" is not set for element {element.ToHtmlPretty()}"); + throw new CardigannException($"Attribute \"{selector.Attribute}\" is not set for element {element.ToHtmlPretty()}"); } } else @@ -909,7 +910,7 @@ namespace NzbDrone.Core.Indexers.Cardigann { var errormessage = "Got redirected to another domain. Try changing the indexer URL to " + domainHint + "."; - throw new Exception(errormessage); + throw new CardigannException(errormessage); } return true; diff --git a/src/NzbDrone.Core/Indexers/Definitions/Cardigann/CardigannConfigException.cs b/src/NzbDrone.Core/Indexers/Definitions/Cardigann/Exceptions/CardigannConfigException.cs similarity index 82% rename from src/NzbDrone.Core/Indexers/Definitions/Cardigann/CardigannConfigException.cs rename to src/NzbDrone.Core/Indexers/Definitions/Cardigann/Exceptions/CardigannConfigException.cs index e8057e991..5986ec0fe 100644 --- a/src/NzbDrone.Core/Indexers/Definitions/Cardigann/CardigannConfigException.cs +++ b/src/NzbDrone.Core/Indexers/Definitions/Cardigann/Exceptions/CardigannConfigException.cs @@ -1,9 +1,9 @@ using NzbDrone.Common.Exceptions; using NzbDrone.Core.Indexers.Cardigann; -namespace NzbDrone.Core.Indexers.Definitions.Cardigann +namespace NzbDrone.Core.Indexers.Definitions.Cardigann.Exceptions { - public class CardigannConfigException : NzbDroneException + public class CardigannConfigException : CardigannException { private readonly CardigannDefinition _configuration; diff --git a/src/NzbDrone.Core/Indexers/Definitions/Cardigann/Exceptions/CardigannException.cs b/src/NzbDrone.Core/Indexers/Definitions/Cardigann/Exceptions/CardigannException.cs new file mode 100644 index 000000000..18ee3644d --- /dev/null +++ b/src/NzbDrone.Core/Indexers/Definitions/Cardigann/Exceptions/CardigannException.cs @@ -0,0 +1,32 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using NzbDrone.Common.Exceptions; + +namespace NzbDrone.Core.Indexers.Definitions.Cardigann.Exceptions +{ + public class CardigannException : NzbDroneException + { + public CardigannException(string message) + : base(message) + { + } + + public CardigannException(string message, params object[] args) + : base(message, args) + { + } + + public CardigannException(string message, Exception innerException) + : base(message, innerException) + { + } + + public CardigannException(string message, Exception innerException, params object[] args) + : base(message, innerException, args) + { + } + } +}