В Kohana исключения обрабатывает системный класс Kohana_Kohana_Exсeption, который отображает страницу ошибки, используя представление
system/views/kohana/error.phpСоздайте класс, унаследовав его от системного,поместив его в
application/classes/kohana/exception.phpКод:
class Kohana_Exception extends Kohana_Kohana_Exception {
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);
}
}
}
}
bootstrap.phpКод:
Route::set('error', 'error/<action>(/<message>)', array('action' => '[0-9]++', 'message' => '.+'))
->defaults(array(
'controller' => 'error'
));
/application/classes/controller/error.phpКод:
class Controller_Error extends Controller {
public function before()
{
parent::before();
// Internal request only!
if (Request::$initial !== Request::$current)
{
if ($message = rawurldecode($this->request->param('message')))
{
$this->template->message = $message;
}
}
else
{
$this->request->action(404);
}
$this->response->status((int) $this->request->action());
}
public function action_404()
{
$this->template->title = 'Not Found 404';
$this->template->content = View::factory('error/404' );
}
public function action_500()
{
$this->template->title = 'Internal Server Error';
$this->template->content = View::factory('error/500' );
}
public function action_503()
{
$this->template->title = 'Maintenance Mode';
$this->template->content = View::factory('error/503' );
}
}
Соответственно должны быть представления: