1
0
mirror of https://github.com/Radarr/Radarr.git synced 2024-11-04 10:02:40 +01:00

log newsnab 429 errors as warn instead of exceptions

This commit is contained in:
Keivan Beigi 2014-10-03 10:50:43 -07:00
parent 7b2e3ef0c4
commit a44be4d902
8 changed files with 66 additions and 53 deletions

View File

@ -50,13 +50,14 @@ public void should_execute_get_using_gzip(string compression)
[TestCase(HttpStatusCode.InternalServerError)]
[TestCase(HttpStatusCode.ServiceUnavailable)]
[TestCase(HttpStatusCode.BadGateway)]
public void should_throw_on_unsuccessful_status_codes(HttpStatusCode statusCode)
[TestCase(429)]
public void should_throw_on_unsuccessful_status_codes(int statusCode)
{
var request = new HttpRequest("http://eu.httpbin.org/status/" + (int)statusCode);
var request = new HttpRequest("http://eu.httpbin.org/status/" + statusCode);
var exception = Assert.Throws<HttpException>(() => Subject.Get<HttpBinResource>(request));
exception.Response.StatusCode.Should().Be(statusCode);
((int)exception.Response.StatusCode).Should().Be(statusCode);
ExceptionVerification.IgnoreWarns();
}

View File

@ -0,0 +1,31 @@
using System;
using NzbDrone.Common.EnvironmentInfo;
namespace NzbDrone.Common.Exceptron
{
public static class ExceptionExtentions
{
private const string IGNORE_FLAG = "exceptron_ignore";
public static Exception ExceptronIgnoreOnMono(this Exception exception)
{
if (OsInfo.IsMono)
{
exception.ExceptronIgnore();
}
return exception;
}
public static Exception ExceptronIgnore(this Exception exception)
{
exception.Data.Add(IGNORE_FLAG, true);
return exception;
}
public static bool ExceptronShouldIgnore(this Exception exception)
{
return exception.Data.Contains(IGNORE_FLAG);
}
}
}

View File

@ -3,39 +3,11 @@
using System.Diagnostics;
using System.Reflection;
using System.Threading;
using NzbDrone.Common.EnvironmentInfo;
using NzbDrone.Common.Exceptron.Configuration;
using NzbDrone.Common.Exceptron.Message;
namespace NzbDrone.Common.Exceptron
{
public static class ExceptionExtentions
{
private const string IgnoreFlag = "exceptron_ignore";
public static Exception ExceptronIgnoreOnMono(this Exception exception)
{
if (OsInfo.IsMono)
{
exception.ExceptronIgnore();
}
return exception;
}
public static Exception ExceptronIgnore(this Exception exception)
{
exception.Data.Add(IgnoreFlag, true);
return exception;
}
public static bool ExceptronShouldIgnore(this Exception exception)
{
return exception.Data.Contains(IgnoreFlag);
}
}
public class ExceptronClient : IExceptronClient
{
internal IRestClient RestClient { private get; set; }

View File

@ -8,7 +8,7 @@ public class HttpException : Exception
public HttpResponse Response { get; private set; }
public HttpException(HttpRequest request, HttpResponse response)
: base(string.Format("HTTP request failed: [{0}] [{1}] at [{2}]", (int)response.StatusCode, request.Method, request.Url.ToString()))
: base(string.Format("HTTP request failed: [{0}:{1}] [{2}] at [{3}]", (int)response.StatusCode, response.StatusCode, request.Method, request.Url.ToString()))
{
Request = request;
Response = response;

View File

@ -103,6 +103,7 @@
<Compile Include="Exceptions\NzbDroneException.cs" />
<Compile Include="Exceptron\Configuration\ExceptronConfiguration.cs" />
<Compile Include="Exceptron\ExceptionData.cs" />
<Compile Include="Exceptron\ExceptionExtentions.cs" />
<Compile Include="Exceptron\ExceptionSeverity.cs" />
<Compile Include="Exceptron\ExceptronApiException.cs" />
<Compile Include="Exceptron\ExceptronClient.cs" />

View File

@ -152,6 +152,15 @@ protected virtual IList<ReleaseInfo> FetchReleases(IList<IEnumerable<IndexerRequ
_logger.Warn("{0} {1} {2}", this, url, webException.Message);
}
}
catch (HttpException httpException)
{
if ((int)httpException.Response.StatusCode == 429)
{
_logger.Warn("API Request Limit reached for {0}", this);
}
_logger.Warn("{0} {1}", this, httpException.Message);
}
catch (RequestLimitReachedException)
{
// TODO: Backoff for x period.

View File

@ -1,12 +1,9 @@
using System;
using System.Collections.Generic;
using System.Linq;
using FluentValidation.Results;
using NLog;
using NzbDrone.Common;
using NzbDrone.Common.Http;
using NzbDrone.Core.Configuration;
using NzbDrone.Core.Indexers.Exceptions;
using NzbDrone.Core.Parser;
using NzbDrone.Core.ThingiProvider;

View File

@ -5,6 +5,7 @@
using NLog;
using NzbDrone.Common;
using NzbDrone.Common.Disk;
using NzbDrone.Common.Exceptron;
using NzbDrone.Common.Instrumentation.Extensions;
using NzbDrone.Core.Configuration;
using NzbDrone.Core.MediaFiles.Events;
@ -49,29 +50,29 @@ private bool ChangeFileDate(EpisodeFile episodeFile, Series series, List<Episode
switch (_configService.FileDate)
{
case FileDateType.LocalAirDate:
{
var airDate = episodes.First().AirDate;
var airTime = series.AirTime;
if (airDate.IsNullOrWhiteSpace() || airTime.IsNullOrWhiteSpace())
{
return false;
}
var airDate = episodes.First().AirDate;
var airTime = series.AirTime;
return ChangeFileDateToLocalAirDate(episodeFilePath, airDate, airTime);
}
if (airDate.IsNullOrWhiteSpace() || airTime.IsNullOrWhiteSpace())
{
return false;
}
return ChangeFileDateToLocalAirDate(episodeFilePath, airDate, airTime);
}
case FileDateType.UtcAirDate:
{
var airDateUtc = episodes.First().AirDateUtc;
if (!airDateUtc.HasValue)
{
return false;
}
var airDateUtc = episodes.First().AirDateUtc;
return ChangeFileDateToUtcAirDate(episodeFilePath, airDateUtc.Value);
}
if (!airDateUtc.HasValue)
{
return false;
}
return ChangeFileDateToUtcAirDate(episodeFilePath, airDateUtc.Value);
}
}
return false;
@ -99,7 +100,7 @@ public void Handle(SeriesScannedEvent message)
if (ChangeFileDate(episodeFile, message.Series, episodesInFile))
{
updated.Add(episodeFile);
}
}
}
if (updated.Any())
@ -163,6 +164,7 @@ private bool ChangeFileDateToUtcAirDate(string filePath, DateTime airDateUtc)
catch (Exception ex)
{
ex.ExceptronIgnoreOnMono();
_logger.WarnException("Unable to set date of file [" + filePath + "]", ex);
}
}