Correctly return HTTP 500 on uncaught exception pages, and also display tracebacks for nested exceptions.

feature/formhandler
Sven Slootweg 10 years ago
parent 7076e8d0fa
commit 4a97d7b0ee

@ -120,6 +120,42 @@ set_exception_handler(function($e){
case "1": case "1":
case "on": case "on":
case "true": case "true":
$inner_exceptions = array();
$inner_e = $e;
while(true)
{
$inner_e = $inner_e->getPrevious();
if($inner_e === null)
{
break;
}
else
{
$inner_exceptions[] = array($inner_e->getMessage(), $inner_e->getTraceAsString());
}
}
if(empty($inner_exceptions))
{
$inner_traces = "";
}
else
{
$inner_traces = "<h2>One or more previous exceptions were also recorded.</h2>";
}
foreach($inner_exceptions as $inner_e)
{
$inner_traces .= "
<p>
<span class='message'>{$inner_e[0]}</span>
</p>
<pre>{$inner_e[1]}</pre>
";
}
$error_body = " $error_body = "
<p> <p>
An uncaught <span class='detail'>{$exception_class}</span> was thrown, in <span class='detail'>{$exception_file}</span> on line <span class='detail'>{$exception_line}</span>. An uncaught <span class='detail'>{$exception_class}</span> was thrown, in <span class='detail'>{$exception_file}</span> on line <span class='detail'>{$exception_line}</span>.
@ -128,6 +164,7 @@ set_exception_handler(function($e){
<span class='message'>{$exception_message}</span> <span class='message'>{$exception_message}</span>
</p> </p>
<pre>{$exception_trace}</pre> <pre>{$exception_trace}</pre>
{$inner_traces}
<p><strong>Important:</strong> These errors should never be displayed on a production server! Make sure that <em>display_errors</em> is turned off in your PHP configuration, if you want to hide these tracebacks.</p> <p><strong>Important:</strong> These errors should never be displayed on a production server! Make sure that <em>display_errors</em> is turned off in your PHP configuration, if you want to hide these tracebacks.</p>
"; ";
break; break;
@ -142,7 +179,9 @@ set_exception_handler(function($e){
"; ";
break; break;
} }
http_status_code(500);
echo(" echo("
<!doctype html> <!doctype html>
<html> <html>
@ -167,6 +206,15 @@ set_exception_handler(function($e){
padding-bottom: 6px; padding-bottom: 6px;
} }
h2
{
color: #575757;
border-bottom: 2px solid #444444;
padding-top: 22px;
padding-bottom: 6px;
font-size: 21px;
}
pre pre
{ {
overflow: auto; overflow: auto;

Loading…
Cancel
Save