mirror of
https://github.com/Radarr/Radarr.git
synced 2024-09-17 15:02:34 +02:00
Handle ratelimit api response for newznab caps endpoint on certain newznab indexers that have caps behind the apikey
This commit is contained in:
parent
7e5d5fe29e
commit
870a39278c
@ -94,8 +94,6 @@ public void should_not_throw_on_xml_data_unexpected()
|
|||||||
var result = Subject.GetCapabilities(_settings);
|
var result = Subject.GetCapabilities(_settings);
|
||||||
|
|
||||||
result.Should().NotBeNull();
|
result.Should().NotBeNull();
|
||||||
|
|
||||||
ExceptionVerification.ExpectedErrors(1);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -328,15 +328,15 @@ protected virtual ValidationFailure TestConnection()
|
|||||||
return new ValidationFailure(string.Empty, "Query successful, but no results were returned from your indexer. This may be an issue with the indexer or your indexer category settings.");
|
return new ValidationFailure(string.Empty, "Query successful, but no results were returned from your indexer. This may be an issue with the indexer or your indexer category settings.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (ApiKeyException)
|
catch (ApiKeyException ex)
|
||||||
{
|
{
|
||||||
_logger.Warn("Indexer returned result for RSS URL, API Key appears to be invalid");
|
_logger.Warn("Indexer returned result for RSS URL, API Key appears to be invalid: " + ex.Message);
|
||||||
|
|
||||||
return new ValidationFailure("ApiKey", "Invalid API Key");
|
return new ValidationFailure("ApiKey", "Invalid API Key");
|
||||||
}
|
}
|
||||||
catch (RequestLimitReachedException)
|
catch (RequestLimitReachedException ex)
|
||||||
{
|
{
|
||||||
_logger.Warn("Request limit reached");
|
_logger.Warn("Request limit reached: " + ex.Message);
|
||||||
}
|
}
|
||||||
catch (CloudFlareCaptchaException ex)
|
catch (CloudFlareCaptchaException ex)
|
||||||
{
|
{
|
||||||
|
@ -67,14 +67,15 @@ private NewznabCapabilities FetchCapabilities(NewznabSettings indexerSettings)
|
|||||||
}
|
}
|
||||||
catch (XmlException ex)
|
catch (XmlException ex)
|
||||||
{
|
{
|
||||||
|
ex.WithData(response, 128 * 1024);
|
||||||
|
_logger.Trace("Unexpected Response content ({0} bytes): {1}", response.ResponseData.Length, response.Content);
|
||||||
_logger.Debug(ex, "Failed to parse newznab api capabilities for {0}", indexerSettings.BaseUrl);
|
_logger.Debug(ex, "Failed to parse newznab api capabilities for {0}", indexerSettings.BaseUrl);
|
||||||
|
|
||||||
ex.WithData(response);
|
|
||||||
throw;
|
throw;
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
_logger.Error(ex, "Failed to determine newznab api capabilities for {0}, using the defaults instead till Radarr restarts", indexerSettings.BaseUrl);
|
ex.WithData(response, 128 * 1024);
|
||||||
|
_logger.Trace("Unexpected Response content ({0} bytes): {1}", response.ResponseData.Length, response.Content);
|
||||||
}
|
}
|
||||||
|
|
||||||
return capabilities;
|
return capabilities;
|
||||||
@ -88,14 +89,16 @@ private NewznabCapabilities ParseCapabilities(HttpResponse response)
|
|||||||
|
|
||||||
if (xDoc == null)
|
if (xDoc == null)
|
||||||
{
|
{
|
||||||
throw new XmlException("Invalid XML");
|
throw new XmlException("Invalid XML").WithData(response);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
NewznabRssParser.CheckError(xDoc, new IndexerResponse(new IndexerRequest(response.Request), response));
|
||||||
|
|
||||||
var xmlRoot = xDoc.Element("caps");
|
var xmlRoot = xDoc.Element("caps");
|
||||||
|
|
||||||
if (xmlRoot == null)
|
if (xmlRoot == null)
|
||||||
{
|
{
|
||||||
throw new XmlException("Unexpected XML");
|
throw new XmlException("Unexpected XML").WithData(response);
|
||||||
}
|
}
|
||||||
|
|
||||||
var xmlLimits = xmlRoot.Element("limits");
|
var xmlLimits = xmlRoot.Element("limits");
|
||||||
|
@ -4,6 +4,7 @@
|
|||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Xml.Linq;
|
using System.Xml.Linq;
|
||||||
using NzbDrone.Common.Extensions;
|
using NzbDrone.Common.Extensions;
|
||||||
|
using NzbDrone.Common.Http;
|
||||||
using NzbDrone.Core.Indexers.Exceptions;
|
using NzbDrone.Core.Indexers.Exceptions;
|
||||||
using NzbDrone.Core.Parser.Model;
|
using NzbDrone.Core.Parser.Model;
|
||||||
|
|
||||||
@ -22,14 +23,13 @@ public NewznabRssParser(NewznabSettings settings)
|
|||||||
_settings = settings;
|
_settings = settings;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override bool PreProcess(IndexerResponse indexerResponse)
|
public static void CheckError(XDocument xdoc, IndexerResponse indexerResponse)
|
||||||
{
|
{
|
||||||
var xdoc = LoadXmlDocument(indexerResponse);
|
|
||||||
var error = xdoc.Descendants("error").FirstOrDefault();
|
var error = xdoc.Descendants("error").FirstOrDefault();
|
||||||
|
|
||||||
if (error == null)
|
if (error == null)
|
||||||
{
|
{
|
||||||
return true;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var code = Convert.ToInt32(error.Attribute("code").Value);
|
var code = Convert.ToInt32(error.Attribute("code").Value);
|
||||||
@ -37,8 +37,7 @@ protected override bool PreProcess(IndexerResponse indexerResponse)
|
|||||||
|
|
||||||
if (code >= 100 && code <= 199)
|
if (code >= 100 && code <= 199)
|
||||||
{
|
{
|
||||||
_logger.Warn("Invalid API Key: {0}", errorMessage);
|
throw new ApiKeyException(errorMessage);
|
||||||
throw new ApiKeyException("Invalid API key");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!indexerResponse.Request.Url.FullUri.Contains("apikey=") && (errorMessage == "Missing parameter" || errorMessage.Contains("apikey")))
|
if (!indexerResponse.Request.Url.FullUri.Contains("apikey=") && (errorMessage == "Missing parameter" || errorMessage.Contains("apikey")))
|
||||||
@ -54,6 +53,15 @@ protected override bool PreProcess(IndexerResponse indexerResponse)
|
|||||||
throw new NewznabException(indexerResponse, errorMessage);
|
throw new NewznabException(indexerResponse, errorMessage);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected override bool PreProcess(IndexerResponse indexerResponse)
|
||||||
|
{
|
||||||
|
var xdoc = LoadXmlDocument(indexerResponse);
|
||||||
|
|
||||||
|
CheckError(xdoc, indexerResponse);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
protected override bool PostProcess(IndexerResponse indexerResponse, List<XElement> items, List<ReleaseInfo> releases)
|
protected override bool PostProcess(IndexerResponse indexerResponse, List<XElement> items, List<ReleaseInfo> releases)
|
||||||
{
|
{
|
||||||
var enclosureTypes = items.SelectMany(GetEnclosures).Select(v => v.Type).Distinct().ToArray();
|
var enclosureTypes = items.SelectMany(GetEnclosures).Select(v => v.Type).Distinct().ToArray();
|
||||||
|
Loading…
Reference in New Issue
Block a user