From 4a97d7b0eeab6666bfe6990a05f1dc7c521b735b Mon Sep 17 00:00:00 2001 From: Sven Slootweg Date: Wed, 2 Apr 2014 23:04:52 +0200 Subject: [PATCH] Correctly return HTTP 500 on uncaught exception pages, and also display tracebacks for nested exceptions. --- base.php | 50 +++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 49 insertions(+), 1 deletion(-) diff --git a/base.php b/base.php index 3cead7c..301f369 100644 --- a/base.php +++ b/base.php @@ -120,6 +120,42 @@ set_exception_handler(function($e){ case "1": case "on": 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 = "

One or more previous exceptions were also recorded.

"; + } + + foreach($inner_exceptions as $inner_e) + { + $inner_traces .= " +

+ {$inner_e[0]} +

+
{$inner_e[1]}
+ "; + } + $error_body = "

An uncaught {$exception_class} was thrown, in {$exception_file} on line {$exception_line}. @@ -128,6 +164,7 @@ set_exception_handler(function($e){ {$exception_message}

{$exception_trace}
+ {$inner_traces}

Important: These errors should never be displayed on a production server! Make sure that display_errors is turned off in your PHP configuration, if you want to hide these tracebacks.

"; break; @@ -142,7 +179,9 @@ set_exception_handler(function($e){ "; break; } - + + http_status_code(500); + echo(" @@ -167,6 +206,15 @@ set_exception_handler(function($e){ padding-bottom: 6px; } + h2 + { + color: #575757; + border-bottom: 2px solid #444444; + padding-top: 22px; + padding-bottom: 6px; + font-size: 21px; + } + pre { overflow: auto;