refactor(AuthClient): Entfernen von ConnectionError und Aktualisierung von tryStartAsync zur Protokollierung

This commit is contained in:
Developer 02 2025-03-05 15:53:57 +01:00
parent 36891b5abb
commit 4e3448b4d4
2 changed files with 10 additions and 25 deletions

View File

@ -4,10 +4,6 @@ public interface IAuthClient : IAuthListenHandler, IAuthSenderHandler
{
bool IsConnected { get; }
Exception? ConnectionError { get; }
bool IsConnectionFailed => ConnectionError is not null;
Task StartAsync();
Task<bool> TryStartAsync();

View File

@ -29,38 +29,27 @@ public class AuthClient : IAuthClient, IAsyncDisposable
_connection.On<string, string, string>(nameof(ReceivePublicKeyAsync), ReceivePublicKeyAsync);
_logger = logger;
_lazyInitiator = new(async () =>
{
try
{
await _connection.StartAsync();
IsConnected = true;
return true;
}
catch(Exception ex)
{
ConnectionError = ex;
throw;
}
});
_logger = logger;
}
public bool IsConnected { get; private set; } = false;
public Exception? ConnectionError { get; private set; }
public async Task StartAsync() => await _lazyInitiator.Value;
public async Task StartAsync()
{
await _connection.StartAsync();
IsConnected = true;
}
public async Task<bool> TryStartAsync()
{
try
{
return await _lazyInitiator.Value;
await StartAsync();
return true;
}
catch
catch(Exception ex)
{
_logger?.LogError(ex, "{message}", ex.Message);
return false;
}
}