From a44be4d902ab1ba7db35c77c938337cfa6ace97f Mon Sep 17 00:00:00 2001 From: Keivan Beigi Date: Fri, 3 Oct 2014 10:50:43 -0700 Subject: [PATCH] log newsnab 429 errors as warn instead of exceptions --- .../Http/HttpClientFixture.cs | 7 ++-- .../Exceptron/ExceptionExtentions.cs | 31 +++++++++++++++ .../Exceptron/ExceptronClient.cs | 28 -------------- src/NzbDrone.Common/Http/HttpException.cs | 2 +- src/NzbDrone.Common/NzbDrone.Common.csproj | 1 + src/NzbDrone.Core/Indexers/HttpIndexerBase.cs | 9 +++++ src/NzbDrone.Core/Indexers/Newznab/Newznab.cs | 3 -- .../MediaFiles/UpdateEpisodeFileService.cs | 38 ++++++++++--------- 8 files changed, 66 insertions(+), 53 deletions(-) create mode 100644 src/NzbDrone.Common/Exceptron/ExceptionExtentions.cs diff --git a/src/NzbDrone.Common.Test/Http/HttpClientFixture.cs b/src/NzbDrone.Common.Test/Http/HttpClientFixture.cs index 02fde70da..b4e78b5ef 100644 --- a/src/NzbDrone.Common.Test/Http/HttpClientFixture.cs +++ b/src/NzbDrone.Common.Test/Http/HttpClientFixture.cs @@ -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(() => Subject.Get(request)); - exception.Response.StatusCode.Should().Be(statusCode); + ((int)exception.Response.StatusCode).Should().Be(statusCode); ExceptionVerification.IgnoreWarns(); } diff --git a/src/NzbDrone.Common/Exceptron/ExceptionExtentions.cs b/src/NzbDrone.Common/Exceptron/ExceptionExtentions.cs new file mode 100644 index 000000000..945ceb0d0 --- /dev/null +++ b/src/NzbDrone.Common/Exceptron/ExceptionExtentions.cs @@ -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); + } + } +} \ No newline at end of file diff --git a/src/NzbDrone.Common/Exceptron/ExceptronClient.cs b/src/NzbDrone.Common/Exceptron/ExceptronClient.cs index a84c64b00..5dca71a4b 100644 --- a/src/NzbDrone.Common/Exceptron/ExceptronClient.cs +++ b/src/NzbDrone.Common/Exceptron/ExceptronClient.cs @@ -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; } diff --git a/src/NzbDrone.Common/Http/HttpException.cs b/src/NzbDrone.Common/Http/HttpException.cs index 3c8e38249..626d17774 100644 --- a/src/NzbDrone.Common/Http/HttpException.cs +++ b/src/NzbDrone.Common/Http/HttpException.cs @@ -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; diff --git a/src/NzbDrone.Common/NzbDrone.Common.csproj b/src/NzbDrone.Common/NzbDrone.Common.csproj index b697320b3..99c966891 100644 --- a/src/NzbDrone.Common/NzbDrone.Common.csproj +++ b/src/NzbDrone.Common/NzbDrone.Common.csproj @@ -103,6 +103,7 @@ + diff --git a/src/NzbDrone.Core/Indexers/HttpIndexerBase.cs b/src/NzbDrone.Core/Indexers/HttpIndexerBase.cs index 6f57b8132..2dc971663 100644 --- a/src/NzbDrone.Core/Indexers/HttpIndexerBase.cs +++ b/src/NzbDrone.Core/Indexers/HttpIndexerBase.cs @@ -152,6 +152,15 @@ protected virtual IList FetchReleases(IList