diff --git a/tools/test-proxy/Azure.Sdk.Tools.TestProxy/Sanitizers/BodyKeySanitizer.cs b/tools/test-proxy/Azure.Sdk.Tools.TestProxy/Sanitizers/BodyKeySanitizer.cs index ac638be0c13..7ed5909994d 100644 --- a/tools/test-proxy/Azure.Sdk.Tools.TestProxy/Sanitizers/BodyKeySanitizer.cs +++ b/tools/test-proxy/Azure.Sdk.Tools.TestProxy/Sanitizers/BodyKeySanitizer.cs @@ -2,7 +2,6 @@ using Newtonsoft.Json; using Newtonsoft.Json.Linq; using System; -using System.Net; namespace Azure.Sdk.Tools.TestProxy.Sanitizers { @@ -44,25 +43,28 @@ public BodyKeySanitizer(string jsonPath, string value = "Sanitized", string rege public override string SanitizeTextBody(string contentType, string body) { bool sanitized = false; - JToken jsonO; + JToken jsonO = null; - try + if (contentType.ToLower().Contains("json")) { - // Prevent default behavior where JSON.NET will convert DateTimeOffset - // into a DateTime. - if (!LegacyConvertJsonDateTokens) + try { - jsonO = JsonConvert.DeserializeObject(body, SerializerSettings); + // Prevent default behavior where JSON.NET will convert DateTimeOffset + // into a DateTime. + if (!LegacyConvertJsonDateTokens) + { + jsonO = JsonConvert.DeserializeObject(body, SerializerSettings); + } + else + { + jsonO = JToken.Parse(body); + } } - else + catch (JsonReaderException) { - jsonO = JToken.Parse(body); + return body; } } - catch(JsonReaderException) - { - return body; - } if (jsonO != null) {