'<', '>' => '>', '"' => '"', "\t" => ' ']);
$error_message = strtr($error_message, ['<br>' => "
", '<br />' => "
", '<b>' => '', '</b>' => '', '<pre>' => '
', '</pre>' => '']); // Generate a bunch of useful information to ease debugging later. $debug_info = self::getDebugInfo(debug_backtrace()); // Log the error in the database. self::logError($error_message, $debug_info, $file, $line); // Are we considering this fatal? Then display and exit. // !!! TODO: should we consider warnings fatal? if (true) // DEBUG || (!DEBUG && $error_level === E_WARNING || $error_level === E_USER_WARNING)) self::display($file . ' (' . $line . ')
Our software could not connect to the database. We apologise for any inconvenience and ask you to check back later.
'; exit; } return $error_message; } public static function display($message, $debug_info, $is_sensitive = true) { $is_admin = Registry::has('user') && Registry::get('user')->isAdmin(); // Just show the message if we're running in a console. if (empty($_SERVER['HTTP_HOST'])) { echo $message; exit; } // JSON request? elseif (isset($_GET['json']) || isset($_GET['format']) && $_GET['format'] == 'json') { if (DEBUG || $is_admin) echo json_encode(['error' => $message . "\n\n" . $debug_info]); elseif (!$is_sensitive) echo json_encode(['error' => $message]); else echo json_encode(['error' => 'Our apologies, an error occured while we were processing your request. Please try again later, or contact us if the problem persists.']); exit; } // Initialise the main template to present a nice message to the user. $page = new MainTemplate('An error occured!'); // Show the error. $is_admin = Registry::has('user') && Registry::get('user')->isAdmin(); if (DEBUG || $is_admin) { $page->adopt(new DummyBox('An error occured!', '' . $message . '
' . $debug_info . '')); // Let's provide the admin navigation despite it all! if ($is_admin) { $page->appendStylesheet(BASEURL . '/css/admin.css'); } } elseif (!$is_sensitive) $page->adopt(new DummyBox('An error occured!', '
' . $message . '
')); else $page->adopt(new DummyBox('An error occured!', 'Our apologies, an error occured while we were processing your request. Please try again later, or contact us if the problem persists.
')); // If we got this far, make sure we're not showing stuff twice. ob_end_clean(); // Render the page. $page->html_main(); exit; } }