Rework some Cardigann exception handling

pull/643/head
Qstick 3 years ago
parent d61ce3f27c
commit 387f8df0ff

@ -10,6 +10,7 @@ using Newtonsoft.Json.Linq;
using NLog; using NLog;
using NzbDrone.Common.Extensions; using NzbDrone.Common.Extensions;
using NzbDrone.Core.Configuration; using NzbDrone.Core.Configuration;
using NzbDrone.Core.Indexers.Definitions.Cardigann.Exceptions;
using NzbDrone.Core.Indexers.Exceptions; using NzbDrone.Core.Indexers.Exceptions;
using NzbDrone.Core.Parser; using NzbDrone.Core.Parser;
using NzbDrone.Core.Parser.Model; using NzbDrone.Core.Parser.Model;
@ -67,7 +68,7 @@ namespace NzbDrone.Core.Indexers.Cardigann
var parsedJson = JToken.Parse(results); var parsedJson = JToken.Parse(results);
if (parsedJson == null) if (parsedJson == null)
{ {
throw new Exception("Error Parsing Json Response"); throw new IndexerException(indexerResponse, "Error Parsing Json Response");
} }
if (search.Rows.Count != null) if (search.Rows.Count != null)
@ -85,7 +86,7 @@ namespace NzbDrone.Core.Indexers.Cardigann
var rowsObj = parsedJson.SelectToken(search.Rows.Selector); var rowsObj = parsedJson.SelectToken(search.Rows.Selector);
if (rowsObj == null) if (rowsObj == null)
{ {
throw new Exception("Error Parsing Rows Selector"); throw new IndexerException(indexerResponse, "Error Parsing Rows Selector");
} }
foreach (var row in rowsObj.Value<JArray>()) foreach (var row in rowsObj.Value<JArray>())
@ -140,7 +141,7 @@ namespace NzbDrone.Core.Indexers.Cardigann
continue; continue;
} }
throw new Exception(string.Format("Error while parsing field={0}, selector={1}, value={2}: {3}", field.Key, field.Value.Selector, value ?? "<null>", ex.Message)); throw new CardigannException(string.Format("Error while parsing field={0}, selector={1}, value={2}: {3}", field.Key, field.Value.Selector, value ?? "<null>", ex.Message));
} }
var filters = search.Rows.Filters; var filters = search.Rows.Filters;
@ -327,7 +328,7 @@ namespace NzbDrone.Core.Indexers.Cardigann
if (value == null && dateHeaders.Optional == false) 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) if (value != null)

@ -12,6 +12,7 @@ using NLog;
using NzbDrone.Common.Http; using NzbDrone.Common.Http;
using NzbDrone.Core.Configuration; using NzbDrone.Core.Configuration;
using NzbDrone.Core.Indexers.Definitions.Cardigann; using NzbDrone.Core.Indexers.Definitions.Cardigann;
using NzbDrone.Core.Indexers.Definitions.Cardigann.Exceptions;
using NzbDrone.Core.IndexerSearch.Definitions; using NzbDrone.Core.IndexerSearch.Definitions;
using NzbDrone.Core.Parser; using NzbDrone.Core.Parser;
using NzbDrone.Core.ThingiProvider; using NzbDrone.Core.ThingiProvider;
@ -288,7 +289,7 @@ namespace NzbDrone.Core.Indexers.Cardigann
} }
catch (Exception ex) 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) 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); var hash = MatchSelector(response, download.Infohash.Hash, variables);
if (hash == null) 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); var title = MatchSelector(response, download.Infohash.Title, variables);
if (title == null) 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); 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); _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); val = element.GetAttribute(selector.Attribute);
if (val == null) 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 else
@ -909,7 +910,7 @@ namespace NzbDrone.Core.Indexers.Cardigann
{ {
var errormessage = "Got redirected to another domain. Try changing the indexer URL to " + domainHint + "."; var errormessage = "Got redirected to another domain. Try changing the indexer URL to " + domainHint + ".";
throw new Exception(errormessage); throw new CardigannException(errormessage);
} }
return true; return true;

@ -1,9 +1,9 @@
using NzbDrone.Common.Exceptions; using NzbDrone.Common.Exceptions;
using NzbDrone.Core.Indexers.Cardigann; 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; private readonly CardigannDefinition _configuration;

@ -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)
{
}
}
}
Loading…
Cancel
Save