Created
February 17, 2011 11:59
-
-
Save smgladkovskiy/831575 to your computer and use it in GitHub Desktop.
Kohana Exception extention
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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