1
0
mirror of https://github.com/bitwarden/server.git synced 2024-11-25 12:45:18 +01:00

Partial revert of #1803 since Azure.Cosmos still uses newtonsoft (#1843)

This commit is contained in:
Oscar Hinton 2022-02-09 13:04:55 +01:00 committed by GitHub
parent 6f86925c6c
commit 11144e70ea
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,8 +1,6 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.Text;
using System.Text.Json;
using Bit.Core.Utilities;
using Microsoft.Azure.Documents; using Microsoft.Azure.Documents;
using Newtonsoft.Json.Linq;
namespace Bit.Admin.Models namespace Bit.Admin.Models
{ {
@ -19,48 +17,40 @@ namespace Bit.Admin.Models
public class LogDetailsModel : LogModel public class LogDetailsModel : LogModel
{ {
public JsonDocument Exception { get; set; } public JObject Exception { get; set; }
public string ExceptionToString(JsonDocument e) public string ExceptionToString(JObject e)
{ {
if (e == null) if (e == null)
{ {
return null; return null;
} }
var root = e.RootElement; var val = string.Empty;
if (e["Message"] != null && e["Message"].ToObject<string>() != null)
var sb = new StringBuilder();
if (root.TryGetProperty("Message", out var messageProp) && messageProp.GetString() != null)
{ {
sb.AppendLine("Message:"); val += "Message:\n";
sb.AppendLine(messageProp.GetString()); val += e["Message"] + "\n";
} }
if (root.TryGetProperty("StackTrace", out var stackTraceProp) && stackTraceProp.GetString() != null) if (e["StackTrace"] != null && e["StackTrace"].ToObject<string>() != null)
{ {
sb.AppendLine(); val += "\nStack Trace:\n";
sb.AppendLine("Stack Trace:"); val += e["StackTrace"];
sb.Append(stackTraceProp.GetString());
} }
else if (root.TryGetProperty("StackTraceString", out var stackTraceStringProp) && stackTraceStringProp.GetString() != null) else if (e["StackTraceString"] != null && e["StackTraceString"].ToObject<string>() != null)
{ {
sb.AppendLine(); val += "\nStack Trace String:\n";
sb.AppendLine("Stack Trace String:"); val += e["StackTraceString"];
sb.Append(stackTraceStringProp.GetString());
} }
if (root.TryGetProperty("InnerException", out var innerExceptionProp) && innerExceptionProp.ValueKind == JsonValueKind.Object) if (e["InnerException"] != null && e["InnerException"].ToObject<JObject>() != null)
{ {
sb.AppendLine(); val += "\n\n=== Inner Exception ===\n\n";
sb.AppendLine(); val += ExceptionToString(e["InnerException"].ToObject<JObject>());
sb.AppendLine("=== Inner Exception ===");
sb.AppendLine();
sb.AppendLine(ExceptionToString(innerExceptionProp.ToObject<JsonDocument>()));
sb.AppendLine();
} }
return sb.ToString(); return val;
} }
} }
} }