Выброс исключения, если в appsettings.json в секции ClientUrl не указан путь до Persistence-сервера
Some checks failed
Unit tests / test (push) Failing after 55s

This commit is contained in:
Оля Бизюкова 2024-12-26 15:47:24 +05:00
parent 6593acbc20
commit d0cd647849
2 changed files with 13 additions and 2 deletions

View File

@ -53,6 +53,7 @@
<PackageReference Include="Refit" Version="8.0.0" /> <PackageReference Include="Refit" Version="8.0.0" />
<PackageReference Include="Refit.HttpClientFactory" Version="8.0.0" /> <PackageReference Include="Refit.HttpClientFactory" Version="8.0.0" />
<PackageReference Include="RestSharp" Version="112.1.0" /> <PackageReference Include="RestSharp" Version="112.1.0" />
<PackageReference Include="System.Configuration.ConfigurationManager" Version="9.0.0" />
<PackageReference Include="System.IdentityModel.Tokens.Jwt" Version="8.3.0" /> <PackageReference Include="System.IdentityModel.Tokens.Jwt" Version="8.3.0" />
</ItemGroup> </ItemGroup>

View File

@ -1,7 +1,9 @@
using DD.Persistence.Client.Clients.Interfaces.Refit; using DD.Persistence.Client.Clients.Interfaces.Refit;
using DD.Persistence.Client.Helpers; using DD.Persistence.Client.Helpers;
using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Logging;
using Refit; using Refit;
using System.Configuration;
using System.Text.Json; using System.Text.Json;
namespace DD.Persistence.Client; namespace DD.Persistence.Client;
@ -18,11 +20,19 @@ public class RefitClientFactory<T> : IRefitClientFactory<T> where T : IRefitClie
/// <summary> /// <summary>
/// ///
/// </summary> /// </summary>
public RefitClientFactory(IConfiguration configuration) public RefitClientFactory(IConfiguration configuration, ILogger<IRefitClientFactory<T>> logger)
{ {
this.client = new HttpClient(); this.client = new HttpClient();
var baseUrl = configuration.GetSection("ClientUrl").Get<string>()!; var baseUrl = configuration.GetSection("ClientUrl").Get<string>();
if (String.IsNullOrEmpty(baseUrl))
{
var exception = new SettingsPropertyNotFoundException("В настройках конфигурации не указан адрес Persistence сервиса.");
logger.LogError(exception.Message);
throw exception;
}
client.BaseAddress = new Uri(baseUrl); client.BaseAddress = new Uri(baseUrl);
client.Authorize(configuration); client.Authorize(configuration);