assorted: fix response status checks

This commit is contained in:
Bogdan
2023-06-18 12:44:40 +03:00
parent df02e2dcf1
commit cc44db15a4
2 changed files with 22 additions and 6 deletions

View File

@@ -184,19 +184,32 @@ namespace Jackett.Common.Indexers.Abstract
var episodeSearchUrl = SearchUrl + "?" + qc.GetQueryString(); var episodeSearchUrl = SearchUrl + "?" + qc.GetQueryString();
var response = await RequestWithCookiesAndRetryAsync(episodeSearchUrl, headers: GetSearchHeaders()); var response = await RequestWithCookiesAndRetryAsync(episodeSearchUrl, headers: GetSearchHeaders());
if (response.Status == HttpStatusCode.Unauthorized || response.Status == HttpStatusCode.PreconditionFailed) if (response.Status == HttpStatusCode.Unauthorized || response.Status == HttpStatusCode.PreconditionFailed)
{ {
await RenewalTokenAsync(); await RenewalTokenAsync();
response = await RequestWithCookiesAndRetryAsync(episodeSearchUrl, headers: GetSearchHeaders()); 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 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 try
{ {
var jsonContent = JToken.Parse(response.ContentString); var jsonContent = JToken.Parse(response.ContentString);
foreach (var row in jsonContent.Value<JArray>("data")) foreach (var row in jsonContent.Value<JArray>("data"))
{ {
var details = new Uri(row.Value<string>("url")); var details = new Uri(row.Value<string>("url"));
@@ -265,6 +278,7 @@ namespace Jackett.Common.Indexers.Abstract
{ {
OnParseError(response.ContentString, ex); OnParseError(response.ContentString, ex);
} }
return releases; return releases;
} }

View File

@@ -214,16 +214,18 @@ namespace Jackett.Common.Indexers.Abstract
await ApplyConfiguration(null); await ApplyConfiguration(null);
response = await RequestWithCookiesAndRetryAsync(searchUrl); 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. // reason for failure should be explained.
var jsonError = JObject.Parse(response.ContentString); var jsonError = JObject.Parse(response.ContentString);
var errorReason = (string)jsonError["error"]; var errorReason = (string)jsonError["error"];
throw new Exception(errorReason); 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 try