Skip to content

Instantly share code, notes, and snippets.

@Javlopez
Created March 29, 2012 19:16
Show Gist options
  • Save Javlopez/2242361 to your computer and use it in GitHub Desktop.
Save Javlopez/2242361 to your computer and use it in GitHub Desktop.
Kohana_Exception
<?php
class Kohana_Exception extends Kohana_Kohana_Exception {
static public function handler(Exception $e)
{
if (Kohana::$environment === Kohana::DEVELOPMENT)
{
parent::handler($e);
}
else
{
Kohana::$log->add(Kohana_Log::ERROR, Kohana_Exception::text($e));
$request = array(
// 500 error by default
'controller' => 'error',
'action' => 500,
// If exception has a message this can be passed on
'id' => rawurlencode($e->getMessage()),
);
// Override status if HTTP_Exception thrown
if ($e instanceof HTTP_Exception)
{
$request['action'] = $e->getCode();
}
if($e instanceof HTTP_Exception_404)
{
$request['id'] = 'La url a la que intento ingresar no existe';
$request['action'] = 404;
}
if (Kohana::$environment === Kohana::DEVELOPMENT)
{
throw $e;
}
echo Request::factory(Route::get('default')->uri($request))
->execute()
->send_headers()
->body();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment