Skip to content

Commit 534ec39

Browse files
Addressing further Copilot's feedback
1 parent 5f0a72e commit 534ec39

File tree

1 file changed

+5
-16
lines changed

1 file changed

+5
-16
lines changed

DevProxy.Plugins/Mocking/MockResponsePlugin.cs

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -607,7 +607,8 @@ private static void ReplacePlaceholders(MockResponseResponse? response, Request
607607
}
608608
}
609609

610-
#pragma warning disable CA1859 // Return type must be object because we can return any type from the request
610+
#pragma warning disable CA1859
611+
// CA1859: This method must return object? because it may return different concrete types (string, int, bool, etc.) based on the JSON content.
611612
private static object? ReplacePlaceholderInString(string value, JsonElement requestBody, ILogger logger)
612613
#pragma warning restore CA1859
613614
{
@@ -640,24 +641,12 @@ private static void ReplacePlaceholders(MockResponseResponse? response, Request
640641
{
641642
// Split the property path by dots to handle nested properties
642643
var propertyNames = propertyPath.Split('.');
643-
644-
// Handle JsonElement
645-
if (requestBody is JsonElement element)
646-
{
647-
return GetNestedValueFromJsonElement(element, propertyNames, logger);
648-
}
649-
else
650-
{
651-
// Handle other dynamic types by converting to JsonElement
652-
var json = JsonSerializer.Serialize(requestBody);
653-
var jsonElement = JsonSerializer.Deserialize<JsonElement>(json);
654-
return GetNestedValueFromJsonElement(jsonElement, propertyNames, logger);
655-
}
644+
return GetNestedValueFromJsonElement(requestBody, propertyNames, logger);
656645
}
657-
catch
646+
catch (Exception ex)
658647
{
659648
// If we can't get the property, return null
660-
logger.LogDebug("Failed to get value for {PropertyPath}. Returning null", propertyPath);
649+
logger.LogDebug(ex, "Failed to get value for {PropertyPath}. Returning null", propertyPath);
661650
}
662651

663652
return null;

0 commit comments

Comments
 (0)