From c537d290c3a9426c62c69b4cfb9bc3e69bca2daa Mon Sep 17 00:00:00 2001 From: Ramon Smits Date: Sat, 19 Aug 2023 13:59:14 +0200 Subject: [PATCH] Only logging "Client will now throw an _MqttConnectingFailedException_." warning when actually throwing the exception (#1801) * Warning was always logged Warning was always logged while the text states it would throw a `MqttConnectingFailedException` exception * Update ReleaseNotes.md --------- Co-authored-by: Christian <6939810+chkr1011@users.noreply.github.com> --- .github/workflows/ReleaseNotes.md | 1 + Source/MQTTnet/Client/MqttClient.cs | 7 +++---- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/ReleaseNotes.md b/.github/workflows/ReleaseNotes.md index f9abc621b..5ee275ee8 100644 --- a/.github/workflows/ReleaseNotes.md +++ b/.github/workflows/ReleaseNotes.md @@ -1,4 +1,5 @@ * [Client] Fixed _PlatformNotSupportedException_ when using Blazor (#1755, thanks to @Nickztar). +* [Client] Fixed wrong logging of obsolete feature when connection was not successful (#1801, thanks to @ramonsmits). * [Client] Fixed _NullReferenceException_ when performing several actions when not connected (#1800, thanks to @ramonsmits). * [Server] Fixed _NullReferenceException_ in retained messages management (#1762, thanks to @logicaloud). * [Server] Exposed new option which allows disabling packet fragmentation (#1753). diff --git a/Source/MQTTnet/Client/MqttClient.cs b/Source/MQTTnet/Client/MqttClient.cs index 938348e85..8556484e2 100644 --- a/Source/MQTTnet/Client/MqttClient.cs +++ b/Source/MQTTnet/Client/MqttClient.cs @@ -465,11 +465,10 @@ async Task Authenticate(IMqttChannelAdapter channelAdap // did send a proper ACK packet with a non success response. if (options.ThrowOnNonSuccessfulConnectResponse) { - _logger.Warning( - "Client will now throw an _MqttConnectingFailedException_. This is obsolete and will be removed in the future. Consider setting _ThrowOnNonSuccessfulResponseFromServer=False_ in client options."); - if (result.ResultCode != MqttClientConnectResultCode.Success) { + _logger.Warning( + "Client will now throw an _MqttConnectingFailedException_. This is obsolete and will be removed in the future. Consider setting _ThrowOnNonSuccessfulResponseFromServer=False_ in client options."); throw new MqttConnectingFailedException($"Connecting with MQTT server failed ({result.ResultCode}).", null, result); } } @@ -1060,4 +1059,4 @@ async Task TrySendKeepAliveMessages(CancellationToken cancellationToken) } } } -} \ No newline at end of file +}