From 8624e044c8d03eeb292f452bab444758c0c1065d 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 (cherry picked from commit 059a156f4a34c6b9cbe139fa1973b814e8a534ae) Closes #3799 --- .../ImportLists/Lidarr/LidarrV1Proxy.cs | 25 ++++++++++++++----- 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/src/NzbDrone.Core/ImportLists/Lidarr/LidarrV1Proxy.cs b/src/NzbDrone.Core/ImportLists/Lidarr/LidarrV1Proxy.cs index f8e1ad5fb..4fcead4f2 100644 --- a/src/NzbDrone.Core/ImportLists/Lidarr/LidarrV1Proxy.cs +++ b/src/NzbDrone.Core/ImportLists/Lidarr/LidarrV1Proxy.cs @@ -69,13 +69,19 @@ namespace NzbDrone.Core.ImportLists.Lidarr return new ValidationFailure("ApiKey", "API Key is invalid"); } - _logger.Error(ex, "Unable to send test message"); - return new ValidationFailure("ApiKey", "Unable to send test message"); + if (ex.Response.HasHttpRedirect) + { + _logger.Error(ex, "Lidarr returned redirect and is invalid"); + return new ValidationFailure("BaseUrl", "Lidarr 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."); } catch (Exception ex) { - _logger.Error(ex, "Unable to send test message"); - return new ValidationFailure("", "Unable to send test message"); + _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."); } return null; @@ -90,11 +96,18 @@ namespace NzbDrone.Core.ImportLists.Lidarr 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;