mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
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
This commit is contained in:
parent
fd175cdbd3
commit
5d3e815967
@ -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;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,7 +1,9 @@
|
|||||||
<?php
|
<?php
|
||||||
/**
|
/**
|
||||||
* ErrorPage holds the content for the page of an error response.
|
* ErrorPage holds the content for the page of an error response.
|
||||||
|
*
|
||||||
* @package cms
|
* @package cms
|
||||||
|
* @usedby Debug::friendlyError()
|
||||||
*/
|
*/
|
||||||
class ErrorPage extends Page {
|
class ErrorPage extends Page {
|
||||||
|
|
||||||
|
@ -229,6 +229,7 @@ class Debug {
|
|||||||
* @param unknown_type $errcontext
|
* @param unknown_type $errcontext
|
||||||
*/
|
*/
|
||||||
static function fatalHandler($errno, $errstr, $errfile, $errline, $errcontext) {
|
static function fatalHandler($errno, $errstr, $errfile, $errline, $errcontext) {
|
||||||
|
|
||||||
if(self::$send_errors_to) self::emailError(self::$send_errors_to, $errno, $errstr, $errfile, $errline, $errcontext, "Error");
|
if(self::$send_errors_to) self::emailError(self::$send_errors_to, $errno, $errstr, $errfile, $errline, $errcontext, "Error");
|
||||||
self::log_error_if_necessary( $errno, $errstr, $errfile, $errline, $errcontext, "Error");
|
self::log_error_if_necessary( $errno, $errstr, $errfile, $errline, $errcontext, "Error");
|
||||||
|
|
||||||
@ -236,32 +237,47 @@ class Debug {
|
|||||||
Debug::showError($errno, $errstr, $errfile, $errline, $errcontext, "Error");
|
Debug::showError($errno, $errstr, $errfile, $errline, $errcontext, "Error");
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
Debug::friendlyError($errno, $errstr, $errfile, $errline, $errcontext);
|
Debug::friendlyError();
|
||||||
}
|
}
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Render a user-facing error page, using the default HTML error template
|
* Render a user-facing error page, using the default HTML error template
|
||||||
* if it exists.
|
* rendered by {@link ErrorPage} if it exists. Doesn't use the standard {@link HTTPResponse} class
|
||||||
|
* the keep dependencies minimal.
|
||||||
|
*
|
||||||
|
* @uses ErrorPage
|
||||||
*
|
*
|
||||||
* @param unknown_type $errno
|
* @param int $statusCode HTTP Status Code (Default: 500)
|
||||||
* @param unknown_type $errstr
|
* @param string $friendlyErrorMessage User-focused error message. Should not contain code pointers or "tech-speak".
|
||||||
* @param unknown_type $errfile
|
* Used in the HTTP Header and ajax responses.
|
||||||
* @param unknown_type $errline
|
* @param string $friendlyErrorDetail Detailed user-focused message. Is just used if no {@link ErrorPage} is found
|
||||||
* @param unknown_type $errcontext
|
* for this specific status code.
|
||||||
|
* @return string HTML error message for non-ajax requests, plaintext for ajax-request.
|
||||||
*/
|
*/
|
||||||
static function friendlyError($errno, $errstr, $errfile, $errline, $errcontext) {
|
static function friendlyError($statusCode = 500, $friendlyErrorMessage = null, $friendlyErrorDetail = null) {
|
||||||
header("HTTP/1.0 500 There has been an error");
|
if(!$friendlyErrorMessage) $friendlyErrorMessage = 'There has been an error';
|
||||||
|
if(!$friendlyErrorDetail) $friendlyErrorDetail = 'The website server has not been able to respond to your request.';
|
||||||
|
|
||||||
|
if(!headers_sent()) header($_SERVER['SERVER_PROTOCOL'] . " $statusCode $friendlyErrorMessage");
|
||||||
|
|
||||||
if(Director::is_ajax()) {
|
if(Director::is_ajax()) {
|
||||||
echo "There has been an error";
|
echo $friendlyErrorMessage;
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
if(file_exists(ASSETS_PATH . '/error-500.html')) {
|
if(file_exists(ASSETS_PATH . "/error-$statusCode.html")) {
|
||||||
include(ASSETS_PATH . '/error-500.html');
|
echo file_get_contents(ASSETS_PATH . "/error-$statusCode.html");
|
||||||
} else {
|
} else {
|
||||||
echo "<h1>Error</h1><p>The website server has not been able to respond to your request.</p>\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()) {
|
if(!headers_sent()) {
|
||||||
$errText = "$errtype: \"$errstr\" at line $errline of $errfile";
|
$errText = "$errtype: \"$errstr\" at line $errline of $errfile";
|
||||||
$errText = str_replace(array("\n","\r")," ",$errText);
|
$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 error is displayed through ajax with CliDebugView, use plaintext output
|
||||||
if(Director::is_ajax()) header('Content-Type: text/plain');
|
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']['message'] = "You need to login with developer access to make use of debugging tools.";
|
||||||
$_SESSION['Security']['Message']['type'] = 'warning';
|
$_SESSION['Security']['Message']['type'] = 'warning';
|
||||||
$_SESSION['BackURL'] = $_SERVER['REQUEST_URI'];
|
$_SESSION['BackURL'] = $_SERVER['REQUEST_URI'];
|
||||||
header("HTTP/1.1 302 Found");
|
header($_SERVER['SERVER_PROTOCOL'] . " 302 Found");
|
||||||
header("Location: " . Director::baseURL() . "Security/login");
|
header("Location: " . Director::baseURL() . "Security/login");
|
||||||
die();
|
die();
|
||||||
}
|
}
|
||||||
|
@ -150,6 +150,13 @@ class DebugView {
|
|||||||
Debug::backtrace();
|
Debug::backtrace();
|
||||||
echo '</div>';
|
echo '</div>';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string $text
|
||||||
|
*/
|
||||||
|
function writeParagraph($text) {
|
||||||
|
echo '<p class="info">' . $text . '</p>';
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
?>
|
?>
|
Loading…
Reference in New Issue
Block a user