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; }