refactor(AuthClient): Entfernen von ConnectionError und Aktualisierung von tryStartAsync zur Protokollierung
This commit is contained in:
parent
36891b5abb
commit
4e3448b4d4
@ -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();
|
||||
|
||||
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user