From 5d3e815967292559273ecb2ddd43330e313e2971 Mon Sep 17 00:00:00 2001 From: Ingo Schommer Date: Wed, 1 Oct 2008 14:43:43 +0000 Subject: [PATCH] API CHANGE Changed parameters for Debug::friendlyError() ENHANCEMENT Using DebugView class in Debug::friendlyError() ENHANCEMENT Using Debug::friendlyError() in HTTPResponse class if status code signifies error (only on live environments in non-ajax requests) ENHANCEMENT Showing contact information in Debug::friendlyError() from Email::getAdminEmail() git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@63465 467b73ca-7a2a-4603-9d3b-597d59a354a9 --- core/control/HTTPResponse.php | 7 ++++- core/model/ErrorPage.php | 2 ++ dev/Debug.php | 48 +++++++++++++++++++++++------------ dev/DebugView.php | 7 +++++ 4 files changed, 47 insertions(+), 17 deletions(-) diff --git a/core/control/HTTPResponse.php b/core/control/HTTPResponse.php index 25a9b46c0..35c6dc65d 100644 --- a/core/control/HTTPResponse.php +++ b/core/control/HTTPResponse.php @@ -183,7 +183,12 @@ class HTTPResponse extends Object { } } - echo $this->body; + if(Director::isLive() && $this->isError()) { + Debug::friendlyError($this->statusCode, $this->getStatusDescription()); + } else { + echo $this->body; + } + } } diff --git a/core/model/ErrorPage.php b/core/model/ErrorPage.php index 0ea5009e8..f73051367 100755 --- a/core/model/ErrorPage.php +++ b/core/model/ErrorPage.php @@ -1,7 +1,9 @@ Error

The website server has not been able to respond to your request.

\n"; + $renderer = new DebugView(); + $renderer->writeHeader(); + $renderer->writeInfo("Website Error", $friendlyErrorMessage, $friendlyErrorDetail); + + if(Email::getAdminEmail()) { + $mailto = Email::obfuscate(Email::getAdminEmail()); + $renderer->writeParagraph('Contact an administrator: ' . $mailto . ''); + } + + $renderer->writeFooter(); } } } @@ -288,7 +304,7 @@ class Debug { if(!headers_sent()) { $errText = "$errtype: \"$errstr\" at line $errline of $errfile"; $errText = str_replace(array("\n","\r")," ",$errText); - header("HTTP/1.0 500 $errText"); + if(!headers_sent()) header($_SERVER['SERVER_PROTOCOL'] . " 500 $errText"); // if error is displayed through ajax with CliDebugView, use plaintext output if(Director::is_ajax()) header('Content-Type: text/plain'); @@ -598,7 +614,7 @@ class Debug { $_SESSION['Security']['Message']['message'] = "You need to login with developer access to make use of debugging tools."; $_SESSION['Security']['Message']['type'] = 'warning'; $_SESSION['BackURL'] = $_SERVER['REQUEST_URI']; - header("HTTP/1.1 302 Found"); + header($_SERVER['SERVER_PROTOCOL'] . " 302 Found"); header("Location: " . Director::baseURL() . "Security/login"); die(); } diff --git a/dev/DebugView.php b/dev/DebugView.php index 95f448966..75844d1bd 100644 --- a/dev/DebugView.php +++ b/dev/DebugView.php @@ -150,6 +150,13 @@ class DebugView { Debug::backtrace(); echo ''; } + + /** + * @param string $text + */ + function writeParagraph($text) { + echo '

' . $text . '

'; + } } ?> \ No newline at end of file