Skip to content

Commit

Permalink
Fix Exception handler fatalerrorexception issues
Browse files Browse the repository at this point in the history
  • Loading branch information
wellingguzman committed Feb 27, 2016
1 parent 376780a commit 6a29a0b
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 2 deletions.
39 changes: 39 additions & 0 deletions api/core/Directus/Exception/ExceptionHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ public function handleException($e)
$e = new FatalThrowableError($e);
}

if('production' !== DIRECTUS_ENV) {
$this->render($e);
}

Hook::run('application.error', $e);
}

Expand All @@ -71,4 +75,39 @@ protected function isFatal($type)
{
return in_array($type, [E_ERROR, E_CORE_ERROR, E_COMPILE_ERROR, E_PARSE]);
}

public function render($e)
{
$content = [];
$trace = $e->getTrace();

$content[] = '<p class="error_backtrace">';
$content[] = '<ol>';
foreach($trace as $item)
$content[] = '<li>' . (isset($item['file']) ? $item['file'] : '<unknown file>') . ' ' . (isset($item['line']) ? $item['line'] : '<unknown line>') . ' calling ' . $item['function'] . '()</li>';
$content[] = '</ol>';
$content[] = '</div>';

$content = implode(PHP_EOL, $content);

echo $this->getExceptionContent($content);
}

public function getExceptionContent($content)
{
return <<<EOF
<!DOCTYPE html>
<html>
<head>
<meta name="robots" content="noindex,nofollow" />
<style>
html { background: #eee; padding: 10px }
</style>
</head>
<body>
$content
</body>
</html>
EOF;
}
}
21 changes: 19 additions & 2 deletions api/core/Directus/Exception/FatalErrorException.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,25 @@
<?php

/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Directus\Exception;

/**
* Fatal Error Exception.
*
* @author Konstanton Myakshin <koc-dp@yandex.ru>
*/
class FatalErrorException extends \ErrorException
{

protected function setTrace($trace)
{
$traceReflector = new \ReflectionProperty('Exception', 'trace');
$traceReflector->setAccessible(true);
$traceReflector->setValue($this, $trace);
}
}

0 comments on commit 6a29a0b

Please sign in to comment.