Fixed: (Apps) Ensure validation for test connection

This commit is contained in:
Bogdan
2023-06-26 13:19:08 +03:00
parent e0e1b1494e
commit 6880e67507
21 changed files with 277 additions and 245 deletions
@@ -3,9 +3,9 @@ using System.Collections.Generic;
using System.Linq;
using System.Net.Http;
using FluentValidation.Results;
using Newtonsoft.Json;
using NLog;
using NzbDrone.Common.Http;
using NzbDrone.Common.Serializer;
namespace NzbDrone.Core.Applications.LazyLibrarian
{
@@ -139,11 +139,11 @@ namespace NzbDrone.Core.Applications.LazyLibrarian
return new ValidationFailure("ApiKey", status.Error.Message);
}
var indexers = GetIndexers(settings);
GetIndexers(settings);
}
catch (HttpException ex)
{
_logger.Error(ex, "Unable to send test message");
_logger.Error(ex, "Unable to complete application test");
return new ValidationFailure("BaseUrl", "Unable to complete application test");
}
catch (LazyLibrarianException ex)
@@ -153,8 +153,8 @@ namespace NzbDrone.Core.Applications.LazyLibrarian
}
catch (Exception ex)
{
_logger.Error(ex, "Unable to send test message");
return new ValidationFailure("", "Unable to send test message");
_logger.Error(ex, "Unable to complete application test");
return new ValidationFailure("", $"Unable to send test message. {ex.Message}");
}
return null;
@@ -164,7 +164,9 @@ namespace NzbDrone.Core.Applications.LazyLibrarian
{
var baseUrl = settings.BaseUrl.TrimEnd('/');
var requestBuilder = new HttpRequestBuilder(baseUrl).Resource(resource)
var requestBuilder = new HttpRequestBuilder(baseUrl)
.Resource(resource)
.Accept(HttpAccept.Json)
.AddQueryParam("cmd", command)
.AddQueryParam("apikey", settings.ApiKey);
@@ -191,9 +193,12 @@ namespace NzbDrone.Core.Applications.LazyLibrarian
{
var response = _httpClient.Execute(request);
var results = JsonConvert.DeserializeObject<TResource>(response.Content);
if ((int)response.StatusCode >= 300)
{
throw new HttpException(response);
}
return results;
return Json.Deserialize<TResource>(response.Content);
}
private int CalculatePriority(int indexerPriority) => ProwlarrHighestPriority - indexerPriority + 1;