From 7e86bea85a86353eaed814a36f56813f966e153f Mon Sep 17 00:00:00 2001 From: bakerboy448 <55419169+bakerboy448@users.noreply.github.com> Date: Sat, 16 Apr 2022 16:43:51 -0500 Subject: [PATCH] fixup! Fixed: Better Indexer Response Handling --- .../Definitions/Cardigann/CardigannParser.cs | 15 --------------- src/NzbDrone.Core/Indexers/HttpIndexerBase.cs | 18 ++++++++++++++---- 2 files changed, 14 insertions(+), 19 deletions(-) diff --git a/src/NzbDrone.Core/Indexers/Definitions/Cardigann/CardigannParser.cs b/src/NzbDrone.Core/Indexers/Definitions/Cardigann/CardigannParser.cs index d88027d43..24547c998 100644 --- a/src/NzbDrone.Core/Indexers/Definitions/Cardigann/CardigannParser.cs +++ b/src/NzbDrone.Core/Indexers/Definitions/Cardigann/CardigannParser.cs @@ -49,21 +49,6 @@ namespace NzbDrone.Core.Indexers.Cardigann CookiesUpdater(null, null); throw new IndexerException(indexerResponse, "We are being redirected to the login page. Most likely your session expired or was killed. Try testing the indexer in the settings."); } - - // Catch common http exceptions before parsing - switch (indexerResponseStatus) - { - case HttpStatusCode.BadRequest: - case HttpStatusCode.Forbidden: - case HttpStatusCode.BadGateway: - case HttpStatusCode.ServiceUnavailable: - case HttpStatusCode.GatewayTimeout: - throw new HttpException(indexerResponse.HttpResponse); - case HttpStatusCode.Unauthorized: - throw new IndexerAuthException(indexerResponse.HttpResponse.Content.ToString()); - default: - throw new IndexerException(indexerResponse, $"Unexpected response status {indexerResponseStatus} code from API request"); - } } var results = indexerResponse.Content; diff --git a/src/NzbDrone.Core/Indexers/HttpIndexerBase.cs b/src/NzbDrone.Core/Indexers/HttpIndexerBase.cs index 1c8474f19..80b845c4c 100644 --- a/src/NzbDrone.Core/Indexers/HttpIndexerBase.cs +++ b/src/NzbDrone.Core/Indexers/HttpIndexerBase.cs @@ -398,11 +398,21 @@ namespace NzbDrone.Core.Indexers // Throw common http errors here before we try to parse if (response.HasHttpError) { - _logger.Warn("HTTP Error - {0}", response); - - if (response.StatusCode == HttpStatusCode.TooManyRequests) + _logger.Warn("HTTP Error - {0}", response); + switch (response.StatusCode) { - throw new TooManyRequestsException(request.HttpRequest, response); + case HttpStatusCode.BadRequest: + case HttpStatusCode.Forbidden: + case HttpStatusCode.BadGateway: + case HttpStatusCode.ServiceUnavailable: + case HttpStatusCode.GatewayTimeout: + throw new HttpException(response); + case HttpStatusCode.TooManyRequests: + throw new TooManyRequestsException(request.HttpRequest, response); + case HttpStatusCode.Unauthorized: + throw new IndexerAuthException(response.Content.ToString()); + default: + throw new HttpException(response); } }