From cc44db15a4d1455fee66b962abdd1c0de985b33a Mon Sep 17 00:00:00 2001 From: Bogdan Date: Sun, 18 Jun 2023 12:44:40 +0300 Subject: [PATCH] assorted: fix response status checks --- .../Indexers/Abstract/AvistazTracker.cs | 20 ++++++++++++++++--- .../Indexers/Abstract/GazelleTracker.cs | 8 +++++--- 2 files changed, 22 insertions(+), 6 deletions(-) diff --git a/src/Jackett.Common/Indexers/Abstract/AvistazTracker.cs b/src/Jackett.Common/Indexers/Abstract/AvistazTracker.cs index 312daf13c..f1333496b 100644 --- a/src/Jackett.Common/Indexers/Abstract/AvistazTracker.cs +++ b/src/Jackett.Common/Indexers/Abstract/AvistazTracker.cs @@ -184,19 +184,32 @@ namespace Jackett.Common.Indexers.Abstract var episodeSearchUrl = SearchUrl + "?" + qc.GetQueryString(); var response = await RequestWithCookiesAndRetryAsync(episodeSearchUrl, headers: GetSearchHeaders()); + if (response.Status == HttpStatusCode.Unauthorized || response.Status == HttpStatusCode.PreconditionFailed) { await RenewalTokenAsync(); response = await RequestWithCookiesAndRetryAsync(episodeSearchUrl, headers: GetSearchHeaders()); } - else if (response.Status == HttpStatusCode.NotFound) + + if (response.Status == HttpStatusCode.NotFound) + { return releases; // search without results, eg CinemaZ: tt0075998 - else if (response.Status != HttpStatusCode.OK) - throw new Exception($"Unknown error: {response.ContentString}"); + } + + if ((int)response.Status >= 400) + { + throw new Exception($"Invalid status code {(int)response.Status} ({response.Status}) received from indexer"); + } + + if (response.Status != HttpStatusCode.OK) + { + throw new Exception($"Unknown status code: {(int)response.Status} ({response.Status})"); + } try { var jsonContent = JToken.Parse(response.ContentString); + foreach (var row in jsonContent.Value("data")) { var details = new Uri(row.Value("url")); @@ -265,6 +278,7 @@ namespace Jackett.Common.Indexers.Abstract { OnParseError(response.ContentString, ex); } + return releases; } diff --git a/src/Jackett.Common/Indexers/Abstract/GazelleTracker.cs b/src/Jackett.Common/Indexers/Abstract/GazelleTracker.cs index 0b164a869..ed883da61 100644 --- a/src/Jackett.Common/Indexers/Abstract/GazelleTracker.cs +++ b/src/Jackett.Common/Indexers/Abstract/GazelleTracker.cs @@ -214,16 +214,18 @@ namespace Jackett.Common.Indexers.Abstract await ApplyConfiguration(null); response = await RequestWithCookiesAndRetryAsync(searchUrl); } - else if (response.ContentString != null && response.ContentString.Contains("failure") && useApiKey) + + if (response.ContentString != null && response.ContentString.Contains("failure") && useApiKey) { // reason for failure should be explained. var jsonError = JObject.Parse(response.ContentString); var errorReason = (string)jsonError["error"]; throw new Exception(errorReason); } - else if ((int)response.Status >= 400) + + if ((int)response.Status >= 400) { - throw new Exception($"Invalid status code {response.Status} received from indexer"); + throw new Exception($"Invalid status code {(int)response.Status} ({response.Status}) received from indexer"); } try