Skip to content

Commit

Permalink
Improved error handling for #776:
Browse files Browse the repository at this point in the history
 * If $cfg['display_errors'] is TRUE, a better looking page is displayed.
 * Otherwise a message is sent to standard PHP error log and a user sees "503 Service Temporarily Unavailable" page. Template can be overriden as error.503.tpl in your theme.
  • Loading branch information
trustmaster committed Jan 19, 2012
1 parent c307967 commit a9d6442
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 11 deletions.
2 changes: 2 additions & 0 deletions lang/en/message.en.lang.php
Expand Up @@ -88,6 +88,8 @@

$L['msg500_title'] = '500 Internal Server Error';
$L['msg500_body'] = 'The server encountered an internal error or misconfiguration and was unable to complete your request. <br />Please contact the administrator and inform them of the time the error occurred, and anything you might have done that may have caused the error.';
$L['msg503_title'] = '503 Service Temporarily Unavailable';
$L['msg503_body'] = 'The page you requested is temporarily unavailable for technical reasons.<br />Please try again later or contact the site administrator.';

/**
* Forum Messages
Expand Down
4 changes: 3 additions & 1 deletion lang/ru/message.ru.lang.php
Expand Up @@ -87,7 +87,9 @@
*/

$L['msg500_title'] = 'Внутренняя ошибка сервера (500)';
$L['msg500_body'] = 'Произошла внутренняя ошибка сервера или ошибка в его конфигурации. <br />Пожалуйста свяжитесь с администратором сайта и сообщите об ошибке и вызвавших ее действиях.';
$L['msg500_body'] = 'Произошла внутренняя ошибка сервера или ошибка в его конфигурации. <br />Пожалуйста, свяжитесь с администратором сайта и сообщите об ошибке и вызвавших ее действиях.';
$L['msg503_title'] = 'Сервис временно недоступен (503)';
$L['msg503_body'] = 'Запрошенная вами страница временно недоступна по техническим причинам.<br />Пожалуйста, повторите попытку позже или свяжитесь с администратором сайта.';

/**
* Forum Messages
Expand Down
29 changes: 19 additions & 10 deletions system/functions.php
Expand Up @@ -2398,19 +2398,27 @@ function cot_diefatal($text='Reason is unknown.', $title='Fatal error')
{
global $cfg;

$env['status'] = '500 Internal Server Error';
if ($cfg['display_errors'])
{
echo "<strong><a href=\"".$cfg['mainurl']."\">".$cfg['maintitle']."</a></strong><br/>";
echo @date('Y-m-d H:i')."<p>$title: $text</p>";
echo '<pre>';
$message_body = '<p><em>'.@date('Y-m-d H:i').'</em></p>';
$message_body .= '<p>'.$text.'</p>';
ob_clean();
debug_print_backtrace();
echo '</pre>';
exit;
$backtrace = ob_get_contents();
ob_clean();
$message_body .= '<pre style="overflow:auto">'.$backtrace.'</pre>';
$message_body .= '<hr /><a href="'.$cfg['mainurl'].'">'.$cfg['maintitle'].'</a>';
cot_die_message(500, true, $title, $message_body);
}
else
{
cot_die_message(500, true);
$backtrace = debug_backtrace();
if (isset($backtrace[1]))
{
$text .= ' in file ' . $backtrace[1]['file'] . ' at line ' . $backtrace[1]['line'] . ' function ' . $backtrace[1]['function'] . '(' . implode(', ', $backtrace[1]['args']) . ')';
}
error_log("$title: $text");
cot_die_message(503, true);
}
}

Expand All @@ -2420,7 +2428,7 @@ function cot_diefatal($text='Reason is unknown.', $title='Fatal error')
* @param int $code Message code
* @param bool $header Render page header
*/
function cot_die_message($code, $header = TRUE)
function cot_die_message($code, $header = TRUE, $message_title = '', $message_body = '')
{
// Globals and requirements
global $cfg, $env, $error_string, $out, $L, $R;
Expand Down Expand Up @@ -2456,6 +2464,7 @@ function cot_die_message($code, $header = TRUE)
403 => '403 Forbidden',
404 => '404 Not Found',
500 => '500 Internal Server Error',
503 => '503 Service Unavailable',
602 => '403 Forbidden',
603 => '403 Forbidden',
900 => '503 Service Unavailable',
Expand All @@ -2474,8 +2483,8 @@ function cot_die_message($code, $header = TRUE)
cot_sendheaders('text/html', $msg_status[$code]);

// Determine message title and body
$title = $L['msg' . $code . '_title'];
$body = $L['msg' . $code . '_body'];
$title = empty($message_title) ? $L['msg' . $code . '_title'] : $message_title;
$body = empty($message_body) ? $L['msg' . $code . '_body'] : $message_body;

// Render the message page
$tpl_type = defined('COT_ADMIN') ? 'core' : 'module';
Expand Down

0 comments on commit a9d6442

Please sign in to comment.