public static function handler(Exception $e) { if (Kohana::$environment !== Kohana::PRODUCTION) { parent::handler($e); } else { try { //not saving 404 as error if ($e->getCode() != 404) { Kohana::$log->add(Log::ERROR, parent::text($e)); } $params = array('action' => 500, 'origuri' => rawurlencode(Arr::get($_SERVER, 'REQUEST_URI')), 'message' => rawurlencode($e->getMessage())); if ($e instanceof HTTP_Exception) { $params['action'] = $e->getCode(); } //d($params); // Error sub-request. echo Request::factory(Route::get('error')->uri($params))->execute()->send_headers()->body(); } catch (Exception $e) { // Clean the output buffer if one exists ob_get_level() and ob_clean(); // Display the exception text echo parent::text($e); // Exit with an error status exit(1); } } }
public static function handlers(Exception $e) { die; if (stripos(get_class($e), 'Smarty')) { echo 'Smarty Found'; } if (Kohana::DEVELOPMENT === Kohana::$environment) { parent::handler($e); } else { try { Kohana::$log->add(Log::ERROR, parent::text($e)); $attributes = array('code' => 500, 'e' => rawurlencode($e->getMessage())); if ($e instanceof HTTP_Exception) { $attributes['code'] = $e->getCode(); } // Error sub-request. echo Request::factory(Route::get('error')->uri($attributes))->execute()->send_headers()->body(); } catch (Exception $e) { // Clean the output buffer if one exists ob_get_level() and ob_clean(); // Display the exception text echo parent::text($e); // Exit with an error status exit(1); } } }
public static function response(Exception $e) { // get the response $response = parent::response($e); // Log the Exception, Kohana_Exception::log($e); if (Kohana::DEVELOPMENT !== Kohana::$environment) { try { // fire error subrequest // directly output result echo Request::factory(Route::get('error')->uri(array('controller' => 'error', 'action' => 'view')))->post('exception', $e)->execute()->send_headers()->body(); exit; } catch (Exception $e) { // Clean the output buffer if one exists ob_get_level() and ob_clean(); // Display the exception text echo parent::text($e); // Exit with an error status exit; } } // end all output buffering $ob = ob_get_level(); for ($i = 0; $i < $ob; $i++) { ob_end_clean(); } // return the response as usual return $response; }
public static function handler(Exception $e) { if (Kohana::$environment == Kohana::DEVELOPMENT) { return parent::handler($e); } try { $params = array('action' => rawurlencode('thrown'), 'code' => base64_encode($e instanceof HTTP_Exception ? $e->getCode() : 500), 'message' => base64_encode($e->getMessage())); die(Request::factory(Route::get('exception')->uri($params))->execute()->send_headers()->body()); } catch (Exception $e2) { ob_clean(); die("A fatal error has occurred: " . parent::text($e2)); } }
/** * Get a Response object representing the exception * * @uses Kohana_Exception::text * @param Exception $e * @return Response */ public static function response($e) { if (Kohana::$environment === Kohana::DEVELOPMENT) { // Show the normal Kohana error page. return parent::response($e); } else { // Lets log the Exception, Just in case it's important! Kohana::$log->add(Log::ERROR, parent::text($e)); // Generate a nicer looking "Oops" page. $view = View::factory('pages/error/default', array('message' => $e->getMessage())); $response = Response::factory()->status(500)->body($view->render()); return $response; } }
protected static function _show_error($error, $attributes, $route = 'error') { // Логируем ошибку Kohana::$log->add(Log::ERROR, parent::text($error))->write(); try { echo Request::factory(Route::url($route, $attributes))->execute()->send_headers()->body(); } catch (Exception $e) { // Clean the output buffer if one exists ob_get_level() and ob_clean(); // Display the exception text echo parent::text($e); // Log error Kohana::$log->add(Log::ERROR, parent::text($e))->write(); // Exit with an error status exit(1); } }
/** * Inline exception handler, displays the error message, source of the * exception, and the stack trace of the error. * * @uses Kohana_Exception::text * @param object exception object * @return boolean */ public static function handler(Exception $e) { if (Kohana::DEVELOPMENT === Kohana::$environment or Kohana::$is_cli) { return parent::handler($e); } else { try { Kohana::$log->add(Log::ERROR, parent::text($e)); $attributes = array('action' => 500, 'message' => rawurlencode($e->getMessage())); // чтобы для админки вызывался свой контроллер ошибок $route_name = 'error'; $route = Request::initial()->route(); if ($route) { $reserved_routes = Kohana::$config->load('admin/site.reserved_routes'); if (in_array($route->route_name, $reserved_routes)) { $route_name = 'admin_error'; } } if ($e instanceof HTTP_Exception) { $attributes['action'] = $e->getCode(); } // Clean the output buffer ob_get_level() and ob_clean(); // Start an output buffer ob_start(); // Error sub-request. echo Request::factory(Route::get($route_name)->uri($attributes))->execute()->send_headers()->body(); // Display the contents of the output buffer echo ob_get_clean(); exit; } catch (Exception $e) { // Clean the output buffer if one exists ob_get_level() and ob_clean(); // Display the exception text echo parent::text($e); // Exit with an error status exit(1); } } }
public static function handler(Exception $e) { // Стандартная обработка, если проект на стадии разработки if (Kohana::DEVELOPMENT === Kohana::$environment) { parent::handler($e); } else { try { // Пишем в лог Kohana::$log->add(Log::ERROR, parent::text($e)); $attributes = array('action' => 500, 'message' => rawurlencode($e->getMessage())); // Получаем код ошибки, как название экшена if ($e instanceof HTTP_Exception) { $attributes['action'] = $e->getCode(); } // Выполняем запрос, обращаясь к роутеру для обработки ошибок echo Request::factory(Route::get('error')->uri($attributes))->execute()->send_headers()->body(); } catch (Exception $e) { // Чистим буфер и выводим текст ошибки ob_get_level() and ob_clean(); echo parent::text($e); exit(1); } } }
/** * Exception handler. * * @static * @param Exception $e * @return boolean */ public static function handler(Exception $e) { // Development environment shows all exceptions if (Kohana::$environment === Kohana::DEVELOPMENT) { return parent::handler($e); } try { // Log errors Kohana::$log->add(Log::ERROR, self::text($e)); // Figure out error page attributes $params = array('action' => 500, 'message' => rawurlencode($e->getMessage())); if ($e instanceof HTTP_Exception) { // Different errors pages for different HTTP errors $params['action'] = $e->getCode(); } else { if ($e instanceof ReflectionException) { // This really shouldn't happen, ever $params['action'] = 404; } else { if ($e instanceof Controller_API_Exception) { // API error $params['action'] = 403; } } } // Display error page echo Request::factory(Route::url('error', $params))->execute()->send_headers()->body(); } catch (Exception $e) { // Clean buffers ob_get_level() and ob_clean(); // Display exception echo parent::text($e); // Exit with error exit(1); } }
/** * Inline exception handler, displays the error message, source of the * exception, and the stack trace of the error. * * @uses Kohana_Exception::text * @param object exception object * @return boolean */ public static function handler(Exception $e) { if (Kohana::DEVELOPMENT === Kohana::$environment or Kohana::$is_cli) { return parent::handler($e); } try { // Get the exception information $type = get_class($e); $code = $e->getCode(); $message = strip_tags($e->getMessage()); $file = Debug::path($e->getFile()); $line = $e->getLine(); if ($e instanceof ErrorException) { if (isset(Kohana_Exception::$php_errors[$code])) { // Use the human-readable error name $code = Kohana_Exception::$php_errors[$code]; } } // Create a text version of the exception $error = "{$type} [{$code}]: {$message} ~ {$file} [{$line}]"; if (is_object(Kohana::$log)) { // Add this exception to the log Kohana::$log->add(Log::ERROR, $error); // Make sure the logs are written Kohana::$log->write(); } // Clean the output buffer ob_get_level() and ob_clean(); // Make sure the proper http header is sent $http_header_status = $e instanceof HTTP_Exception ? $e->getCode() : 500; // Make correct title $title = isset(Response::$messages[$http_header_status]) ? Response::$messages[$http_header_status] : $type; if (!headers_sent()) { header('Content-Type: ' . Kohana_Exception::$error_view_content_type . '; charset=' . Kohana::$charset, TRUE, $http_header_status); } if (Request::$current !== NULL and Request::current()->is_ajax() === TRUE) { // Just display the text of the exception echo "\n{$type} [{$code}]: {$message}\n"; // Exit with an error status exit(1); } else { // Start an output buffer ob_start(); // Include the exception HTML if ($view_file = Kohana::find_file('views', Kohana_Exception::$frontend_error_view . '/' . $http_header_status)) { // Include custom exception view include $view_file; } if ($view_file = Kohana::find_file('views', Kohana_Exception::$frontend_error_view)) { // Include common exception view include $view_file; } else { throw new Kohana_Exception('Error view file does not exist: views/:file', array(':file' => Kohana_Exception::$frontend_error_view)); } // Display the contents of the output buffer echo ob_get_clean(); // Exit with an error status exit(1); } } catch (Exception $e) { // Clean the output buffer if one exists ob_get_level() and ob_clean(); // Display the exception text echo parent::text($e); // Exit with an error status exit(1); } }