From 5714b6312d912fc407bdd4a7f5209ac642a803fe Mon Sep 17 00:00:00 2001 From: Luis Cantero Date: Thu, 25 Jul 2024 14:36:06 +0200 Subject: [PATCH] Improve err check --- src/PlcServer.cs | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/src/PlcServer.cs b/src/PlcServer.cs index be5ee755..198bb5f5 100644 --- a/src/PlcServer.cs +++ b/src/PlcServer.cs @@ -216,7 +216,7 @@ public override ResponseHeader Publish( return responseHeader; } - catch (Exception ex) + catch (ServiceResultException ex) { MetricsHelper.RecordTotalErrors(nameof(Publish)); @@ -227,7 +227,7 @@ public override ResponseHeader Publish( results = default; diagnosticInfos = default; - if (ex.Message == StatusCodes.BadNoSubscription.ToString()) + if (ex.StatusCode == StatusCodes.BadNoSubscription) { _logger.LogDebug( "Failed to publish: {StatusCode}", @@ -236,7 +236,7 @@ public override ResponseHeader Publish( return new ResponseHeader { ServiceResult = StatusCodes.BadNoSubscription }; } - if (ex.Message == StatusCodes.BadSessionIdInvalid.ToString()) + if (ex.StatusCode == StatusCodes.BadSessionIdInvalid) { _logger.LogDebug( "Failed to publish: {StatusCode}", @@ -245,7 +245,7 @@ public override ResponseHeader Publish( return new ResponseHeader { ServiceResult = StatusCodes.BadSessionIdInvalid }; } - if (ex.Message == StatusCodes.BadSecureChannelIdInvalid.ToString()) + if (ex.StatusCode == StatusCodes.BadSecureChannelIdInvalid) { _logger.LogDebug( "Failed to publish: {StatusCode}", @@ -254,6 +254,13 @@ public override ResponseHeader Publish( return new ResponseHeader { ServiceResult = StatusCodes.BadSecureChannelIdInvalid }; } + _logger.LogError(ex, "Error publishing"); + throw; + } + catch(Exception ex) + { + MetricsHelper.RecordTotalErrors(nameof(Publish)); + _logger.LogError(ex, "Error publishing"); throw; }