log newsnab 429 errors as warn instead of exceptions

pull/2/head
Keivan Beigi 10 years ago
parent 7b2e3ef0c4
commit a44be4d902

@ -50,13 +50,14 @@ namespace NzbDrone.Common.Test.Http
[TestCase(HttpStatusCode.InternalServerError)] [TestCase(HttpStatusCode.InternalServerError)]
[TestCase(HttpStatusCode.ServiceUnavailable)] [TestCase(HttpStatusCode.ServiceUnavailable)]
[TestCase(HttpStatusCode.BadGateway)] [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)); var exception = Assert.Throws<HttpException>(() => Subject.Get<HttpBinResource>(request));
exception.Response.StatusCode.Should().Be(statusCode); ((int)exception.Response.StatusCode).Should().Be(statusCode);
ExceptionVerification.IgnoreWarns(); ExceptionVerification.IgnoreWarns();
} }

@ -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);
}
}
}

@ -3,39 +3,11 @@ using System.Collections.Generic;
using System.Diagnostics; using System.Diagnostics;
using System.Reflection; using System.Reflection;
using System.Threading; using System.Threading;
using NzbDrone.Common.EnvironmentInfo;
using NzbDrone.Common.Exceptron.Configuration; using NzbDrone.Common.Exceptron.Configuration;
using NzbDrone.Common.Exceptron.Message; using NzbDrone.Common.Exceptron.Message;
namespace NzbDrone.Common.Exceptron 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 public class ExceptronClient : IExceptronClient
{ {
internal IRestClient RestClient { private get; set; } internal IRestClient RestClient { private get; set; }

@ -8,7 +8,7 @@ namespace NzbDrone.Common.Http
public HttpResponse Response { get; private set; } public HttpResponse Response { get; private set; }
public HttpException(HttpRequest request, HttpResponse response) 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; Request = request;
Response = response; Response = response;

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

@ -152,6 +152,15 @@ namespace NzbDrone.Core.Indexers
_logger.Warn("{0} {1} {2}", this, url, webException.Message); _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) catch (RequestLimitReachedException)
{ {
// TODO: Backoff for x period. // TODO: Backoff for x period.

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

@ -5,6 +5,7 @@ using System.Linq;
using NLog; using NLog;
using NzbDrone.Common; using NzbDrone.Common;
using NzbDrone.Common.Disk; using NzbDrone.Common.Disk;
using NzbDrone.Common.Exceptron;
using NzbDrone.Common.Instrumentation.Extensions; using NzbDrone.Common.Instrumentation.Extensions;
using NzbDrone.Core.Configuration; using NzbDrone.Core.Configuration;
using NzbDrone.Core.MediaFiles.Events; using NzbDrone.Core.MediaFiles.Events;
@ -49,29 +50,29 @@ namespace NzbDrone.Core.MediaFiles
switch (_configService.FileDate) switch (_configService.FileDate)
{ {
case FileDateType.LocalAirDate: 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;
}
case FileDateType.UtcAirDate: return ChangeFileDateToLocalAirDate(episodeFilePath, airDate, airTime);
{ }
var airDateUtc = episodes.First().AirDateUtc;
if (!airDateUtc.HasValue) case FileDateType.UtcAirDate:
{ {
return false; var airDateUtc = episodes.First().AirDateUtc;
}
return ChangeFileDateToUtcAirDate(episodeFilePath, airDateUtc.Value); if (!airDateUtc.HasValue)
} {
return false;
}
return ChangeFileDateToUtcAirDate(episodeFilePath, airDateUtc.Value);
}
} }
return false; return false;
@ -163,6 +164,7 @@ namespace NzbDrone.Core.MediaFiles
catch (Exception ex) catch (Exception ex)
{ {
ex.ExceptronIgnoreOnMono();
_logger.WarnException("Unable to set date of file [" + filePath + "]", ex); _logger.WarnException("Unable to set date of file [" + filePath + "]", ex);
} }
} }

Loading…
Cancel
Save