Refactor JSON handling in network requests

This commit is contained in:
Haiping Chen 2024-07-08 14:10:40 -05:00
parent c8792d3ead
commit a0e44307e0

View file

@ -112,15 +112,19 @@ public class PlaywrightInstance : IDisposable
e.Request.ResourceType == "fetch")
{
Serilog.Log.Information($"fetched: {e.Url}");
JsonElement? json = null;
try
{
var json = await e.JsonAsync();
fetched(e.Url.ToLower(), JsonSerializer.Serialize(json));
json = await e.JsonAsync();
}
catch(Exception ex)
{
Serilog.Log.Error(ex.ToString());
}
finally
{
fetched(e.Url.ToLower(), JsonSerializer.Serialize(json ?? new JsonElement()));
}
}
};
}