From 059a156f4a34c6b9cbe139fa1973b814e8a534ae Mon Sep 17 00:00:00 2001 From: Bogdan Date: Sun, 4 Jun 2023 16:28:57 +0300 Subject: [PATCH] Fixed: Treat redirects as errors in Sonarr Import List --- .../ImportLists/Sonarr/SonarrV3Proxy.cs | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/src/NzbDrone.Core/ImportLists/Sonarr/SonarrV3Proxy.cs b/src/NzbDrone.Core/ImportLists/Sonarr/SonarrV3Proxy.cs index f51cb2f87..2021304ed 100644 --- a/src/NzbDrone.Core/ImportLists/Sonarr/SonarrV3Proxy.cs +++ b/src/NzbDrone.Core/ImportLists/Sonarr/SonarrV3Proxy.cs @@ -69,6 +69,12 @@ namespace NzbDrone.Core.ImportLists.Sonarr return new ValidationFailure("ApiKey", "API Key is invalid"); } + if (ex.Response.HasHttpRedirect) + { + _logger.Error(ex, "Sonarr returned redirect and is invalid"); + return new ValidationFailure("BaseUrl", "Sonarr URL is invalid, are you missing a URL base?"); + } + _logger.Error(ex, "Unable to connect to import list."); return new ValidationFailure(string.Empty, $"Unable to connect to import list: {ex.Message}. Check the log surrounding this error for details."); } @@ -90,11 +96,18 @@ namespace NzbDrone.Core.ImportLists.Sonarr var baseUrl = settings.BaseUrl.TrimEnd('/'); - var request = new HttpRequestBuilder(baseUrl).Resource(resource).Accept(HttpAccept.Json) - .SetHeader("X-Api-Key", settings.ApiKey).Build(); + var request = new HttpRequestBuilder(baseUrl).Resource(resource) + .Accept(HttpAccept.Json) + .SetHeader("X-Api-Key", settings.ApiKey) + .Build(); var response = _httpClient.Get(request); + if ((int)response.StatusCode >= 300) + { + throw new HttpException(response); + } + var results = JsonConvert.DeserializeObject>(response.Content); return results;