Skip to content

Instantly share code, notes, and snippets.

@smgladkovskiy
Created February 17, 2011 11:59
Show Gist options
  • Save smgladkovskiy/831575 to your computer and use it in GitHub Desktop.
Save smgladkovskiy/831575 to your computer and use it in GitHub Desktop.
Kohana Exception extention
<?php defined('SYSPATH') or die('No direct access allowed.');
class Kohana_Exception extends Kohana_Kohana_Exception {
public static function handler(Exception $e)
{
if (Kohana::$environment > Kohana::PRODUCTION)
{
parent::handler($e);
}
else
{
$error_code = $e->getCode();
// Avoid growing of error log
if($error_code != 404)
Kohana::$log->add(Log::ERROR, parent::text($e));
// Attributes for error controller
$attributes = array(
'lang' => I18n::lang(),
'action' => 500, // default action is 500 - for error 500
'message' => rawurldecode($e->getMessage())
);
// Specify action based on HTTP error code
if ($e instanceof HTTP_Exception)
{
$attributes['action'] = $error_code;
$status = $error_code;
}
try
{
echo Request::factory(Route::url('error', $attributes))
->execute()
->status($status)
->send_headers()
->body();
}
catch (Exception $e)
{
parent::handler($e);
}
// Send a email to admin on error occurs
if($error_code != 404)
{
Email::connect();
Email::send(
Kohana::$config->load('email')->admin,
Kohana::$config->load('email')->noreply,
__('Site error!'),
$attributes['message'],
TRUE
);
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment