From 3328ca9593a52fa9198e72a251a31bece7c0d613 Mon Sep 17 00:00:00 2001 From: Luis Cantero Date: Thu, 25 Jul 2024 07:38:07 +0200 Subject: [PATCH] Improve publish BadSessionIdInvalid and BadSecureChannelIdInvalid (#378) * Handle more errors during publish * Update version --- src/PlcServer.cs | 36 ++++++++++++++++++++++++++++-------- version.json | 2 +- 2 files changed, 29 insertions(+), 9 deletions(-) diff --git a/src/PlcServer.cs b/src/PlcServer.cs index 97b0f046..be5ee755 100644 --- a/src/PlcServer.cs +++ b/src/PlcServer.cs @@ -220,20 +220,40 @@ public override ResponseHeader Publish( { MetricsHelper.RecordTotalErrors(nameof(Publish)); + subscriptionId = default; + availableSequenceNumbers = default; + moreNotifications = default; + notificationMessage = default; + results = default; + diagnosticInfos = default; + if (ex.Message == StatusCodes.BadNoSubscription.ToString()) { - _logger.LogDebug("Failed to publish: BadNoSubscription"); - - subscriptionId = default; - availableSequenceNumbers = default; - moreNotifications = default; - notificationMessage = default; - results = default; - diagnosticInfos = default; + _logger.LogDebug( + "Failed to publish: {StatusCode}", + StatusCodes.BadNoSubscription.ToString()); return new ResponseHeader { ServiceResult = StatusCodes.BadNoSubscription }; } + if (ex.Message == StatusCodes.BadSessionIdInvalid.ToString()) + { + _logger.LogDebug( + "Failed to publish: {StatusCode}", + StatusCodes.BadSessionIdInvalid.ToString()); + + return new ResponseHeader { ServiceResult = StatusCodes.BadSessionIdInvalid }; + } + + if (ex.Message == StatusCodes.BadSecureChannelIdInvalid.ToString()) + { + _logger.LogDebug( + "Failed to publish: {StatusCode}", + StatusCodes.BadSecureChannelIdInvalid.ToString()); + + return new ResponseHeader { ServiceResult = StatusCodes.BadSecureChannelIdInvalid }; + } + _logger.LogError(ex, "Error publishing"); throw; } diff --git a/version.json b/version.json index 8462e431..d8b46454 100644 --- a/version.json +++ b/version.json @@ -1,6 +1,6 @@ { "$schema": "https://raw.githubusercontent.com/AArnott/Nerdbank.GitVersioning/master/src/NerdBank.GitVersioning/version.schema.json", - "version": "2.12.18", + "version": "2.12.19", "versionHeightOffset": -1, "publicReleaseRefSpec": [ "^refs/heads/main$",