FrmError & GlobalErrorHandler: Show InnerExceptions

This commit is contained in:
2015-05-25 00:33:25 +02:00
parent ea52ac6ab9
commit c53c79b0c1
2 changed files with 41 additions and 22 deletions

View File

@@ -1,4 +1,5 @@
using System; using System;
using System.Text;
using System.Web; using System.Web;
using Scrummer.Code.Pages; using Scrummer.Code.Pages;
@@ -12,28 +13,39 @@ namespace Scrummer.Code
{ {
context.Response.StatusCode = 500; context.Response.StatusCode = 500;
context.Response.Clear(); context.Response.Clear();
context.Response.Write("<h2>Internal error</h2>");
context.Response.Write(String.Format("<p><b>Message:</b> {0}</p>", ex.Message)); StringBuilder sbOutput = new StringBuilder();
context.Response.Write(String.Format("<p><b>StackTrace:</b></p> <pre><code>{0}</code></pre>", ex.StackTrace)); sbOutput.Append("<h2>Internal error</h2>");
Exception exAux = ex;
if (exAux is HttpUnhandledException && exAux.InnerException != null) { exAux = exAux.InnerException; }
while (exAux != null)
{
sbOutput.AppendFormat("<p><b>Message:</b> {0}</p>", exAux.Message);
sbOutput.AppendFormat("<p><b>StackTrace:</b></p> <pre><code>{0}</code></pre>", exAux.StackTrace);
exAux = exAux.InnerException;
}
// Fill response to 512 bytes to avoid browser "beauty" response of errors. // Fill response to 512 bytes to avoid browser "beauty" response of errors.
long fillResponse = 512 - (ex.Message.Length + ex.StackTrace.Length); ; long fillResponse = 512 - sbOutput.Length;
if (fillResponse > 0) if (fillResponse > 0)
{ {
context.Response.Write("<!--"); sbOutput.Append("<!--");
for (int i = 0; i < fillResponse; i++) for (int i = 0; i < fillResponse; i++)
{ {
context.Response.Write("A"); sbOutput.Append("A");
} }
context.Response.Write("-->"); sbOutput.Append("-->");
} }
context.Response.Write(sbOutput.ToString());
} }
#endregion #endregion
#region Public methods #region Public methods
public static void HandleError(HttpContext context,Exception ex){ public static void HandleError(HttpContext context, Exception ex)
{
try try
{ {
IHttpHandler frmError = new FrmError(ex); IHttpHandler frmError = new FrmError(ex);

View File

@@ -18,24 +18,31 @@ namespace Scrummer.Code.Pages
void FrmError_Init(object sender, EventArgs e) void FrmError_Init(object sender, EventArgs e)
{ {
Title = "Error"; Title = "Application Error";
CLabel lblErrorTitle = new CLabel { Text = "Error", Tag = "h2" }; CLabel lblErrorTitle = new CLabel { Text = Title, Tag = "h2" };
Controls.Add(lblErrorTitle); Controls.Add(lblErrorTitle);
CLabel lblMessage = new CLabel { Tag = "P" }; Exception exAux = _ex;
lblMessage.Text = String.Format("<b>{0}:</b> {1}", "Message",HttpUtility.HtmlEncode(_ex.Message)); if (exAux is HttpUnhandledException && exAux.InnerException != null) { exAux = exAux.InnerException; }
Controls.Add(lblMessage); while (exAux != null)
{
CLabel lblMessage = new CLabel { Tag = "P" };
lblMessage.Text = String.Format("<b>{0}:</b> {1}", "Message", HttpUtility.HtmlEncode(exAux.Message));
Controls.Add(lblMessage);
CLabel lblStacktraceTitle = new CLabel { Tag = "p" }; CLabel lblStacktraceTitle = new CLabel { Tag = "p" };
lblStacktraceTitle.Text = String.Format("<b>{0}:</b>", "Stacktrace"); lblStacktraceTitle.Text = String.Format("<b>{0}:</b>", "Stacktrace");
Controls.Add(lblStacktraceTitle); Controls.Add(lblStacktraceTitle);
Panel pnlStacktrace = new Panel(); Panel pnlStacktrace = new Panel();
pnlStacktrace.CssClass = "divCode"; pnlStacktrace.CssClass = "divCode";
Controls.Add(pnlStacktrace); Controls.Add(pnlStacktrace);
LiteralControl litStackTrace = new LiteralControl( LiteralControl litStackTrace = new LiteralControl(
String.Format("<pre><code>{0}</code></pre>", HttpUtility.HtmlEncode(_ex.StackTrace))); String.Format("<pre><code>{0}</code></pre>", HttpUtility.HtmlEncode(exAux.StackTrace)));
pnlStacktrace.Controls.Add(litStackTrace); pnlStacktrace.Controls.Add(litStackTrace);
exAux = exAux.InnerException;
}
} }
} }
} }