forked from JSONAPIdotNET/JSONAPI.NET
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathExceptionErrorMetadata.cs
More file actions
39 lines (34 loc) · 1.17 KB
/
ExceptionErrorMetadata.cs
File metadata and controls
39 lines (34 loc) · 1.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
using System;
using Newtonsoft.Json.Linq;
namespace JSONAPI.Documents
{
/// <summary>
/// Metadata object for serializing exceptions in a response
/// </summary>
public class ExceptionErrorMetadata : IMetadata
{
/// <summary>
/// Creates a new ExceptionErrorMetadata
/// </summary>
/// <param name="exception"></param>
public ExceptionErrorMetadata(Exception exception)
{
MetaObject = new JObject();
var currentObject = MetaObject;
var currentException = exception;
while (currentException != null)
{
currentObject["exceptionMessage"] = currentException.Message;
currentObject["stackTrace"] = currentException.StackTrace;
currentException = currentException.InnerException;
if (currentException != null)
{
var innerObject = new JObject();
currentObject["innerException"] = innerObject;
currentObject = innerObject;
}
}
}
public JObject MetaObject { get; private set; }
}
}