This repository has been archived on 2024-04-08. You can view files and clone it, but cannot push or open issues or pull requests.
khosb/application/classes/Kohana/Exception.php

75 lines
1.9 KiB
PHP
Raw Permalink Normal View History

2013-10-10 02:44:53 +00:00
<?php defined('SYSPATH') OR die('No direct access');
/**
* Kohana exception class. Translates exceptions using the [I18n] class.
*
* @package OSB
* @category Modifications
* @author Deon George
* @copyright (c) 2009-2013 Open Source Billing
* @license http://dev.osbill.net/license.html
*/
class Kohana_Exception extends Kohana_Kohana_Exception {
/**
* Logs an exception in the database. If that fails fall back to Kohana's Logging.
*
* @uses Kohana_Exception::text
* @param Exception $e
* @param int $level
* @return void
*/
public static function log(Exception $e,$level=Log::EMERGENCY) {
try {
2016-08-25 13:25:32 +00:00
if (class_exists('Model_Log_Error')) {
$eo = ORM::factory('Log_Error');
$eo->message = Kohana_Exception::text($e);
$eo->account_id = (PHP_SAPI === 'cli' OR ! Auth::instance()->logged_in()) ? NULL : Auth::instance()->get_user()->id;
2016-08-25 13:25:32 +00:00
if (Request::current()) {
$eo->module = (Request::current()->directory() ? Request::current()->directory().'_' : '').Request::current()->controller();
$eo->method = Request::current()->action();
}
2016-08-25 13:25:32 +00:00
$eo->save();
}
2013-10-10 02:44:53 +00:00
} catch (Exception $x) {
return parent::log($e,$level);
}
}
/**
* Redirect errors to the main page after showing a system message.
* The error should be logged in the DB.
*
* @param Exception $e
* @return Response
*/
public static function response(Exception $e) {
try {
if (Kohana::$config->load('debug')->show_errors) {
return parent::response($e);
2013-12-04 10:37:09 +00:00
2013-10-10 02:44:53 +00:00
} else {
2016-08-25 13:25:32 +00:00
if (class_exists('SystemMessage')) {
SystemMessage::add(array(
'title'=>'An Error Occured.',
'type'=>'error',
'body'=>'Dont panic, its been logged.',
));
}
2013-10-10 02:44:53 +00:00
// We'll redirect to the main page.
$response = Response::factory();
$response->status(302);
$response->headers('Location',URL::site());
2013-12-04 10:37:09 +00:00
2013-10-10 02:44:53 +00:00
return $response;
}
} catch (Exception $x) {
return parent::response($e);
}
}
}
?>