2014-05-14 23:24:20 +10:00
|
|
|
<?php namespace System\Classes;
|
|
|
|
|
2015-02-16 21:16:43 +11:00
|
|
|
use Log;
|
2014-05-14 23:24:20 +10:00
|
|
|
use View;
|
|
|
|
use Config;
|
|
|
|
use Cms\Classes\Theme;
|
|
|
|
use Cms\Classes\Router;
|
2017-03-14 19:42:37 +11:00
|
|
|
use Cms\Classes\Controller as CmsController;
|
2015-01-28 18:03:35 +11:00
|
|
|
use October\Rain\Exception\ErrorHandler as ErrorHandlerBase;
|
2015-02-19 00:35:14 +11:00
|
|
|
use October\Rain\Exception\ApplicationException;
|
2014-05-14 23:24:20 +10:00
|
|
|
|
|
|
|
/**
|
|
|
|
* System Error Handler, this class handles application exception events.
|
|
|
|
*
|
|
|
|
* @package october\system
|
|
|
|
* @author Alexey Bobkov, Samuel Georges
|
|
|
|
*/
|
2015-01-28 18:03:35 +11:00
|
|
|
class ErrorHandler extends ErrorHandlerBase
|
2014-05-14 23:24:20 +10:00
|
|
|
{
|
2015-05-02 18:11:26 +10:00
|
|
|
/**
|
2017-03-16 06:26:14 +11:00
|
|
|
* @inheritDoc
|
2015-05-02 18:11:26 +10:00
|
|
|
*/
|
2015-06-04 17:37:29 +10:00
|
|
|
// public function handleException(Exception $proposedException)
|
|
|
|
// {
|
|
|
|
// // The Twig runtime error is not very useful
|
|
|
|
// if (
|
|
|
|
// $proposedException instanceof Twig_Error_Runtime &&
|
|
|
|
// ($previousException = $proposedException->getPrevious()) &&
|
|
|
|
// (!$previousException instanceof CmsException)
|
|
|
|
// ) {
|
|
|
|
// $proposedException = $previousException;
|
|
|
|
// }
|
2015-05-02 18:11:26 +10:00
|
|
|
|
2015-06-04 17:37:29 +10:00
|
|
|
// return parent::handleException($proposedException);
|
|
|
|
// }
|
2015-05-02 18:11:26 +10:00
|
|
|
|
2015-02-16 21:16:43 +11:00
|
|
|
/**
|
|
|
|
* We are about to display an error page to the user,
|
2015-02-19 00:35:14 +11:00
|
|
|
* if it is an ApplicationException, this event should be logged.
|
2015-02-16 21:16:43 +11:00
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function beforeHandleError($exception)
|
|
|
|
{
|
2015-02-19 00:35:14 +11:00
|
|
|
if ($exception instanceof ApplicationException) {
|
2015-02-16 21:16:43 +11:00
|
|
|
Log::error($exception);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-05-14 23:24:20 +10:00
|
|
|
/**
|
|
|
|
* Looks up an error page using the CMS route "/error". If the route does not
|
|
|
|
* exist, this function will use the error view found in the Cms module.
|
|
|
|
* @return mixed Error page contents.
|
|
|
|
*/
|
|
|
|
public function handleCustomError()
|
|
|
|
{
|
2016-12-17 10:16:02 +11:00
|
|
|
if (Config::get('app.debug', false)) {
|
2015-01-28 18:03:35 +11:00
|
|
|
return null;
|
2016-12-17 10:16:02 +11:00
|
|
|
}
|
2015-01-28 18:03:35 +11:00
|
|
|
|
2014-05-14 23:24:20 +10:00
|
|
|
$theme = Theme::getActiveTheme();
|
2016-12-17 10:16:02 +11:00
|
|
|
$router = new Router($theme);
|
2014-05-14 23:24:20 +10:00
|
|
|
|
|
|
|
// Use the default view if no "/error" URL is found.
|
2014-10-18 11:58:50 +02:00
|
|
|
if (!$router->findByUrl('/error')) {
|
2014-05-14 23:24:20 +10:00
|
|
|
return View::make('cms::error');
|
2014-10-18 11:58:50 +02:00
|
|
|
}
|
2014-05-14 23:24:20 +10:00
|
|
|
|
|
|
|
// Route to the CMS error page.
|
2017-03-14 19:42:37 +11:00
|
|
|
$controller = new CmsController($theme);
|
2015-04-11 11:19:53 +10:00
|
|
|
$result = $controller->run('/error');
|
|
|
|
|
|
|
|
// Extract content from response object
|
|
|
|
if ($result instanceof \Symfony\Component\HttpFoundation\Response) {
|
|
|
|
$result = $result->getContent();
|
|
|
|
}
|
|
|
|
|
|
|
|
return $result;
|
2014-05-14 23:24:20 +10:00
|
|
|
}
|
2015-01-28 18:03:35 +11:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Displays the detailed system exception page.
|
|
|
|
* @return View Object containing the error page.
|
|
|
|
*/
|
|
|
|
public function handleDetailedError($exception)
|
|
|
|
{
|
|
|
|
// Ensure System view path is registered
|
|
|
|
View::addNamespace('system', base_path().'/modules/system/views');
|
|
|
|
|
|
|
|
return View::make('system::exception', ['exception' => $exception]);
|
|
|
|
}
|
2014-10-18 11:58:50 +02:00
|
|
|
}
|