Skip to content

Commit

Permalink
Add handling for FormatException thrown by invalid feature flag json (#…
Browse files Browse the repository at this point in the history
…551)

* add log for formatexception from invalid feature flag json

* remove capitalized json

* remove unused using

* fix comments

* fix constant reference
  • Loading branch information
amerjusupovic authored Jun 21, 2024
1 parent 6a682ff commit 96a5e5a
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -492,6 +492,12 @@ public async Task<bool> TryRefreshAsync(CancellationToken cancellationToken)

return false;
}
catch (FormatException fe)
{
_logger.LogWarning(LogHelper.BuildRefreshFailedDueToFormattingErrorMessage(fe.Message));

return false;
}

return true;
}
Expand Down Expand Up @@ -634,6 +640,7 @@ exception is KeyVaultReferenceException ||
exception is TimeoutException ||
exception is OperationCanceledException ||
exception is InvalidOperationException ||
exception is FormatException ||
((exception as AggregateException)?.InnerExceptions?.Any(e =>
e is RequestFailedException ||
e is OperationCanceledException) ?? false)))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ internal class LoggingConstants
public const string RefreshFailedDueToKeyVaultError = "A refresh operation failed while resolving a Key Vault reference.";
public const string PushNotificationUnregisteredEndpoint = "Ignoring the push notification received for the unregistered endpoint";
public const string FallbackClientLookupError = "Failed to perform fallback client lookup.";
public const string RefreshFailedDueToFormattingError = "A refresh operation failed due to a formatting error.";

// Successful update, debug log level
public const string RefreshKeyValueRead = "Key-value read from App Configuration.";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ private FeatureFlag ParseFeatureFlag(string settingKey, string settingValue)
}
catch (JsonException e)
{
throw new FormatException(settingKey, e);
throw new FormatException(string.Format(ErrorMessages.FeatureFlagInvalidFormat, settingKey), e);
}

return featureFlag;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,5 +89,10 @@ public static string BuildFallbackClientLookupFailMessage(string exceptionMessag
{
return $"{LoggingConstants.FallbackClientLookupError}\n{exceptionMessage}";
}

public static string BuildRefreshFailedDueToFormattingErrorMessage(string exceptionMessage)
{
return $"{LoggingConstants.RefreshFailedDueToFormattingError}\n{exceptionMessage}";
}
}
}

0 comments on commit 96a5e5a

Please sign in to comment.