/** * Shows a themed error page. * @see Kohana_Exception::handle */ private static function _show_themed_error_page(Exception $e) { // Create a text version of the exception $error = Kohana_Exception::text($e); // Add this exception to the log Kohana_Log::add('error', $error); // Manually save logs after exceptions Kohana_Log::save(); if (!headers_sent()) { if ($e instanceof Kohana_Exception) { $e->sendHeaders(); } else { header("HTTP/1.1 500 Internal Server Error"); } } $view = new Theme_View("page.html", "other", "error"); if ($e instanceof Kohana_404_Exception) { $view->page_title = t("Dang... Page not found!"); $view->content = new View("error_404.html"); $user = identity::active_user(); $view->content->is_guest = $user && $user->guest; if ($view->content->is_guest) { $view->content->login_form = new View("login_ajax.html"); $view->content->login_form->form = auth::get_login_form("login/auth_html"); // Avoid anti-phishing protection by passing the url as session variable. Session::instance()->set("continue_url", url::current(true)); } } else { $view->page_title = t("Dang... Something went wrong!"); $view->content = new View("error.html"); } print $view; }
/** * exception handler, displays the error message, source of the * exception, and the stack trace of the error. * * @uses Kohana::message() * @uses Kohana_Exception::text() * @param object exception object * @return void */ public static function handle(Exception $e) { try { // Get the exception information $type = get_class($e); $code = $e->getCode(); $message = $e->getMessage(); // Create a text version of the exception $error = Kohana_Exception::text($e); // Add this exception to the log Kohana_Log::add('error', $error); // Manually save logs after exceptions Kohana_Log::save(); if (Kohana::config('core.display_errors') === FALSE) { // Do not show the details $file = $line = NULL; $trace = array(); $template = '_disabled'; } else { $file = $e->getFile(); $line = $e->getLine(); $trace = $e->getTrace(); $template = ''; } if ($e instanceof Kohana_Exception) { $template = $e->getTemplate() . $template; if (!headers_sent()) { $e->sendHeaders(); } // Use the human-readable error name $code = Kohana::message('core.errors.' . $code); } else { $template = Kohana_Exception::$template . $template; if (!headers_sent()) { header('HTTP/1.1 500 Internal Server Error'); } if ($e instanceof ErrorException) { // Use the human-readable error name $code = Kohana::message('core.errors.' . $e->getSeverity()); if (version_compare(PHP_VERSION, '5.3', '<')) { // Workaround for a bug in ErrorException::getTrace() that exists in // all PHP 5.2 versions. @see http://bugs.php.net/45895 for ($i = count($trace) - 1; $i > 0; --$i) { if (isset($trace[$i - 1]['args'])) { // Re-position the arguments $trace[$i]['args'] = $trace[$i - 1]['args']; unset($trace[$i - 1]['args']); } } } } } // Clean the output buffer if one exists ob_get_level() and ob_clean(); if ($template = Kohana::find_file('views', $template)) { include $template; } } catch (Exception $e) { // Clean the output buffer if one exists ob_get_level() and ob_clean(); // Display the exception text echo Kohana_Exception::text($e), "\n"; } if (Kohana::$server_api === 'cli') { // Exit with an error status exit(1); } }