Skip to content

Commit

Permalink
Improve err check
Browse files Browse the repository at this point in the history
  • Loading branch information
luiscantero committed Jul 25, 2024
1 parent 3328ca9 commit 5714b63
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions src/PlcServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ public override ResponseHeader Publish(

return responseHeader;
}
catch (Exception ex)
catch (ServiceResultException ex)
{
MetricsHelper.RecordTotalErrors(nameof(Publish));

Expand All @@ -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}",
Expand All @@ -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}",
Expand All @@ -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}",
Expand All @@ -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;
}
Expand Down

0 comments on commit 5714b63

Please sign in to comment.