mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-01-31 17:16:18 +00:00
Merge pull request #79 from tPl0ch/2.0-errorhandler-rewrite
Rewrite of Fix for Ticket #1707.
This commit is contained in:
commit
c30ba40bd5
1 changed files with 21 additions and 20 deletions
|
@ -107,31 +107,32 @@ class ErrorHandler {
|
||||||
* @see http://php.net/manual/en/function.set-exception-handler.php
|
* @see http://php.net/manual/en/function.set-exception-handler.php
|
||||||
*/
|
*/
|
||||||
public static function handleException(Exception $exception) {
|
public static function handleException(Exception $exception) {
|
||||||
|
$config = Configure::read('Exception');
|
||||||
|
if (!empty($config['log'])) {
|
||||||
|
$message = sprintf("[%s] %s\n%s",
|
||||||
|
get_class($exception),
|
||||||
|
$exception->getMessage(),
|
||||||
|
$exception->getTraceAsString()
|
||||||
|
);
|
||||||
|
CakeLog::write(LOG_ERR, $message);
|
||||||
|
}
|
||||||
|
$renderer = $config['renderer'];
|
||||||
|
if ($renderer !== 'ExceptionRenderer') {
|
||||||
|
list($plugin, $renderer) = pluginSplit($renderer, true);
|
||||||
|
App::uses($renderer, $plugin . 'Error');
|
||||||
|
}
|
||||||
try {
|
try {
|
||||||
$config = Configure::read('Exception');
|
|
||||||
if (!empty($config['log'])) {
|
|
||||||
$message = sprintf("[%s] %s\n%s",
|
|
||||||
get_class($exception),
|
|
||||||
$exception->getMessage(),
|
|
||||||
$exception->getTraceAsString()
|
|
||||||
);
|
|
||||||
CakeLog::write(LOG_ERR, $message);
|
|
||||||
}
|
|
||||||
$renderer = $config['renderer'];
|
|
||||||
if ($renderer !== 'ExceptionRenderer') {
|
|
||||||
list($plugin, $renderer) = pluginSplit($renderer, true);
|
|
||||||
App::uses($renderer, $plugin . 'Error');
|
|
||||||
}
|
|
||||||
$error = new $renderer($exception);
|
$error = new $renderer($exception);
|
||||||
$error->render();
|
$error->render();
|
||||||
} catch (Exception $e) {
|
} catch (Exception $e) {
|
||||||
$message = $e->getMessage()."\nCall Stack:\n".$e->getTraceAsString();
|
set_error_handler(Configure::read('Error.handler')); // Should be using configured ErrorHandler
|
||||||
ErrorHandler::handleError(
|
Configure::write('Error.trace', false); // trace is useless here since it's internal
|
||||||
E_ERROR,
|
$message = sprintf("[%s] %s\n%s", // Keeping same message format
|
||||||
$message,
|
get_class($e),
|
||||||
$e->getFile(),
|
$e->getMessage(),
|
||||||
$e->getLine()
|
$e->getTraceAsString()
|
||||||
);
|
);
|
||||||
|
trigger_error($message, E_USER_ERROR);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue