forked from ServiceStack/ServiceStack
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathErrorViewPage.cs
More file actions
68 lines (65 loc) · 2.01 KB
/
ErrorViewPage.cs
File metadata and controls
68 lines (65 loc) · 2.01 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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
using System;
using System.Text;
using ServiceStack.Razor.Templating;
using ServiceStack.Text;
namespace ServiceStack.Razor
{
//The type or namespace name 'Html' does not exist in the namespace 'ServiceStack.Markdown' (are you missing an assembly reference?)
public class ErrorViewPage : ViewPageRef
{
public static string DefaultPageName = "Error";
public static string DefaultContents = @"<!DOCTYPE HTML>
<html>
<head>
<title>Error</title>
<style>
BODY {{
background-color:white;
color:#000000;
font-family:Verdana;
margin: 0;
}}
H1 {{
background-color: #036;
color: #FFF;
font-family: Tahoma;
font-size: 26px;
font-weight: normal;
margin: 0;
padding: 10px 0 3px 15px;
}}
</style>
</head>
<body>
<h1>Oops something went wrong!</h1>
<div style=""padding:10px;"">
<h2>{0}</h2>
<div>{1}</div>
<h3>Stack Trace</h3>
<pre>{2}</pre>
</div>
</body>
</html>";
private Exception ex;
public ErrorViewPage(RazorFormat razorFormat, Exception ex)
: base(razorFormat, null, DefaultPageName, ErrorPage(ex, DefaultContents))
{
this.ex = ex;
}
public static string ErrorPage(Exception ex, string template)
{
var details = "";
var tempEx = ex as TemplateCompilationException;
if (tempEx != null)
{
var sb = new StringBuilder("<h3>Compile Errors</h3>");
foreach (var error in tempEx.Errors)
{
sb.AppendFormat("<p>{0}</p>\n", error.Dump());
}
details = sb.ToString();
}
return template.Fmt(ex.Message + " (" + ex.GetType().Name + ")", details, ex.StackTrace);
}
}
}