diff --git a/tools/test-proxy/Azure.Sdk.Tools.TestProxy/Common/JsonComparer.cs b/tools/test-proxy/Azure.Sdk.Tools.TestProxy/Common/JsonComparer.cs index 469007e5e36..2e237ec83df 100644 --- a/tools/test-proxy/Azure.Sdk.Tools.TestProxy/Common/JsonComparer.cs +++ b/tools/test-proxy/Azure.Sdk.Tools.TestProxy/Common/JsonComparer.cs @@ -1,4 +1,7 @@ +using System; using System.Collections.Generic; +using System.Linq.Expressions; +using System.Text; using System.Text.Json; namespace Azure.Sdk.Tools.TestProxy.Common @@ -7,12 +10,32 @@ public class JsonComparer { public static List CompareJson(byte[] json1, byte[] json2) { + var differences = new List(); + JsonDocument doc1; + JsonDocument doc2; + // Deserialize the byte arrays to JsonDocument - JsonDocument doc1 = JsonDocument.Parse(json1); - JsonDocument doc2 = JsonDocument.Parse(json2); + try + { + doc1 = JsonDocument.Parse(json1); + } + catch(Exception ex) + { + differences.Add($"Unable to parse the request json body. Content \"{Encoding.UTF8.GetString(json1)}.\" Exception: {ex.Message}"); + return differences; + } + + try + { + doc2 = JsonDocument.Parse(json2); + } + + catch (Exception ex) + { + differences.Add($"Unable to parse the record json body. Content \"{Encoding.UTF8.GetString(json2)}.\" Exception: {ex.Message}"); + return differences; + } - // Compare the JSON objects - var differences = new List(); CompareElements(doc1.RootElement, doc2.RootElement, differences, ""); return differences;