1
0
mirror of https://github.com/bitwarden/server.git synced 2025-02-14 01:31:24 +01:00

log exception strings

This commit is contained in:
Kyle Spearrin 2018-03-30 17:35:07 -04:00
parent efd6a89e34
commit c63422ea5d
3 changed files with 40 additions and 15 deletions

View File

@ -70,7 +70,7 @@ namespace Bit.Admin.Controllers
_globalSettings.DocumentDb.Key))
{
var uri = UriFactory.CreateDocumentUri(Database, Collection, id.ToString());
var response = await client.ReadDocumentAsync<LogModel>(uri);
var response = await client.ReadDocumentAsync<LogDetailsModel>(uri);
if(response?.Document == null)
{
return RedirectToAction("Index");

View File

@ -1,9 +1,6 @@
using System;
using System.Collections.Generic;
using System.Runtime.Serialization;
using System.Collections.Generic;
using Microsoft.Azure.Documents;
using Newtonsoft.Json;
using Serilog.Events;
using Newtonsoft.Json.Linq;
namespace Bit.Admin.Models
{
@ -14,18 +11,46 @@ namespace Bit.Admin.Models
public string Message { get; set; }
public string MessageTruncated => Message.Length > 200 ? $"{Message.Substring(0, 200)}..." : Message;
public string MessageTemplate { get; set; }
public Error Exception { get; set; }
public IDictionary<string, object> Properties { get; set; }
public string Project => Properties?.ContainsKey("Project") ?? false ? Properties["Project"].ToString() : null;
}
[JsonObject(MemberSerialization.OptIn)]
public class Error : Exception, ISerializable
public class LogDetailsModel : LogModel
{
public JObject Exception { get; set; }
public string ExceptionToString(JObject e)
{
[JsonProperty(PropertyName = "error")]
public string ErrorMessage { get; set; }
if(e == null)
{
return null;
}
[JsonConstructor]
public Error() { }
var val = string.Empty;
if(e["Message"] != null && e["Message"].ToObject<string>() != null)
{
val += "Message:\n";
val += e["Message"] + "\n";
}
if(e["StackTrace"] != null && e["StackTrace"].ToObject<string>() != null)
{
val += "\nStackTrace:\n";
val += e["StackTrace"];
}
else if(e["StackTraceString"] != null && e["StackTraceString"].ToObject<string>() != null)
{
val += "\nStackTraceString:\n";
val += e["StackTraceString"];
}
if(e["InnerException"] != null && e["InnerException"].ToObject<JObject>() != null)
{
val += "\n\n\n=== Inner Exception ===\n\n\n";
val += ExceptionToString(e["InnerException"].ToObject<JObject>());
}
return val;
}
}
}

View File

@ -1,4 +1,4 @@
@model LogModel
@model LogDetailsModel
@{
ViewData["Title"] = "Log: " + Model.Id;
}
@ -26,7 +26,7 @@
@if(Model.Exception != null)
{
<h2>Exception</h2>
<pre style="max-height: 500px;">@Model.Exception.ToString()</pre>
<pre style="max-height: 500px;">@Model.ExceptionToString(Model.Exception)</pre>
}
@if(Model.Properties != null && Model.Properties.Count > 0)