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.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();
}

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

@ -8,7 +8,7 @@ namespace NzbDrone.Common.Http
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;

@ -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" />

@ -152,6 +152,15 @@ namespace NzbDrone.Core.Indexers
_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.

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

@ -5,6 +5,7 @@ using System.Linq;
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;
@ -163,6 +164,7 @@ namespace NzbDrone.Core.MediaFiles
catch (Exception ex)
{
ex.ExceptronIgnoreOnMono();
_logger.WarnException("Unable to set date of file [" + filePath + "]", ex);
}
}

Loading…
Cancel
Save