Fixed: (Rarbg) Move check response by status code to parser

pull/1649/head
Bogdan 1 year ago
parent 008f238dda
commit 92e7a38bd0

@ -1,7 +1,6 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Threading.Tasks;
using System.Web;
using NLog;
@ -13,7 +12,6 @@ using NzbDrone.Common.Http;
using NzbDrone.Common.Serializer;
using NzbDrone.Core.Configuration;
using NzbDrone.Core.Exceptions;
using NzbDrone.Core.Indexers.Exceptions;
using NzbDrone.Core.IndexerSearch.Definitions;
using NzbDrone.Core.Messaging.Events;
using NzbDrone.Core.Parser;
@ -84,25 +82,6 @@ namespace NzbDrone.Core.Indexers.Definitions.Rarbg
return cleanReleases.Select(r => (ReleaseInfo)r.Clone()).ToList();
}
public static void CheckResponseByStatusCode(IndexerResponse response, Logger logger)
{
var responseCode = (int)response.HttpResponse.StatusCode;
switch (responseCode)
{
case (int)HttpStatusCode.TooManyRequests:
logger.Warn("Indexer API limit reached.");
throw new TooManyRequestsException(response.HttpRequest, response.HttpResponse, TimeSpan.FromMinutes(2));
case 520:
logger.Warn("Indexer API error, likely rate limited by origin server.");
throw new TooManyRequestsException(response.HttpRequest, response.HttpResponse, TimeSpan.FromMinutes(3));
case (int)HttpStatusCode.OK:
break;
default:
throw new IndexerException(response, "Indexer API call returned an unexpected status code [{0}]", responseCode);
}
}
private IndexerCapabilities SetCapabilities()
{
var caps = new IndexerCapabilities
@ -157,7 +136,7 @@ namespace NzbDrone.Core.Indexers.Definitions.Rarbg
{
var response = await base.FetchIndexerResponse(request);
CheckResponseByStatusCode(response, _logger);
((RarbgParser)GetParser()).CheckResponseByStatusCode(response);
// try and recover from token errors
var jsonResponse = new HttpResponse<RarbgResponse>(response.HttpResponse);

@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Net;
using System.Text.RegularExpressions;
using NLog;
using NzbDrone.Common.EnvironmentInfo;
@ -28,7 +29,7 @@ namespace NzbDrone.Core.Indexers.Definitions.Rarbg
{
var results = new List<ReleaseInfo>();
Rarbg.CheckResponseByStatusCode(indexerResponse, _logger);
CheckResponseByStatusCode(indexerResponse);
var jsonResponse = new HttpResponse<RarbgResponse>(indexerResponse.HttpResponse);
@ -99,18 +100,30 @@ namespace NzbDrone.Core.Indexers.Definitions.Rarbg
return results;
}
private string GetGuid(RarbgTorrent torrent)
public void CheckResponseByStatusCode(IndexerResponse response)
{
var match = RegexGuid.Match(torrent.download);
var responseCode = (int)response.HttpResponse.StatusCode;
if (match.Success)
{
return string.Format("rarbg-{0}", match.Groups[1].Value);
}
else
switch (responseCode)
{
return string.Format("rarbg-{0}", torrent.download);
case (int)HttpStatusCode.TooManyRequests:
_logger.Warn("Indexer API limit reached.");
throw new TooManyRequestsException(response.HttpRequest, response.HttpResponse, TimeSpan.FromMinutes(2));
case 520:
_logger.Warn("Indexer API error, likely rate limited by origin server.");
throw new TooManyRequestsException(response.HttpRequest, response.HttpResponse, TimeSpan.FromMinutes(3));
case (int)HttpStatusCode.OK:
break;
default:
throw new IndexerException(response, "Indexer API call returned an unexpected status code [{0}]", responseCode);
}
}
private static string GetGuid(RarbgTorrent torrent)
{
var match = RegexGuid.Match(torrent.download);
return match.Success ? $"rarbg-{match.Groups[1].Value}" : $"rarbg-{torrent.download}";
}
}
}

Loading…
Cancel
Save