From a05e149b31f988e3623b9576b25d0b7598081877 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Philipp=20H=C3=A4felfinger?= Date: Mon, 17 Oct 2022 00:23:40 +0200 Subject: [PATCH] optimizes login method --- PiwigoDotnet/Piwigo.Client/PiwigoContext.cs | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/PiwigoDotnet/Piwigo.Client/PiwigoContext.cs b/PiwigoDotnet/Piwigo.Client/PiwigoContext.cs index 19c62e1..de357e5 100644 --- a/PiwigoDotnet/Piwigo.Client/PiwigoContext.cs +++ b/PiwigoDotnet/Piwigo.Client/PiwigoContext.cs @@ -22,21 +22,22 @@ public class PiwigoContext : IPiwigoContext public async Task LoginAsync() { + if (IsLoggedIn) + { + _logger.LogWarning("The client is already logged in!"); + return; + } + var userName = _config.UserName; if (string.IsNullOrWhiteSpace(userName)) { - throw new ArgumentException("Value cannot be null or whitespace.", nameof(userName)); + throw new PiwigoException("username cannot be null or whitespace."); } var password = _config.Password; if (string.IsNullOrWhiteSpace(password)) { - throw new ArgumentException("Value cannot be null or whitespace.", nameof(password)); - } - - if (IsLoggedIn) - { - throw new PiwigoException("The client is already logged in. Create a new instance or log out first!"); + throw new PiwigoException("password cannot be null or whitespace."); } _logger.LogInformation("Logging into {PiwigoBaseUri} using username {Username}", _config.BaseUri, userName);