mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 03:18:26 +00:00
Fixed nesting when ExceptionRenderer throws exception
This commit is contained in:
parent
d39c744c28
commit
f621bb7fe5
2 changed files with 45 additions and 2 deletions
|
@ -125,6 +125,8 @@ class ErrorHandler {
|
|||
$e->getMessage(),
|
||||
$e->getTraceAsString()
|
||||
);
|
||||
|
||||
Configure::write('Exception.bail', true);
|
||||
trigger_error($message, E_USER_ERROR);
|
||||
}
|
||||
}
|
||||
|
@ -249,10 +251,17 @@ class ErrorHandler {
|
|||
}
|
||||
|
||||
if (Configure::read('debug')) {
|
||||
call_user_func($exceptionHandler, new FatalErrorException($description, 500, $file, $line));
|
||||
$exception = new FatalErrorException($description, 500, $file, $line);
|
||||
} else {
|
||||
call_user_func($exceptionHandler, new InternalErrorException());
|
||||
$exception = new InternalErrorException();
|
||||
}
|
||||
|
||||
if (Configure::read('Exception.bail')) {
|
||||
throw $exception;
|
||||
}
|
||||
|
||||
call_user_func($exceptionHandler, $exception);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
|
@ -20,6 +20,16 @@ App::uses('ErrorHandler', 'Error');
|
|||
App::uses('Controller', 'Controller');
|
||||
App::uses('Router', 'Routing');
|
||||
|
||||
/**
|
||||
* A faulty ExceptionRenderer to test nesting.
|
||||
*/
|
||||
class FaultyExceptionRenderer extends ExceptionRenderer {
|
||||
|
||||
public function render() {
|
||||
throw new Exception('Error from renderer.');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* ErrorHandlerTest class
|
||||
*
|
||||
|
@ -320,4 +330,28 @@ class ErrorHandlerTest extends CakeTestCase {
|
|||
$this->assertContains('[FatalErrorException] Something wrong', $log[1], 'message missing.');
|
||||
}
|
||||
|
||||
/**
|
||||
* testExceptionRendererNestingDebug method
|
||||
*
|
||||
* @expectedException FatalErrorException
|
||||
* @return void
|
||||
*/
|
||||
public function testExceptionRendererNestingDebug() {
|
||||
Configure::write('debug', 2);
|
||||
Configure::write('Exception.renderer', 'FaultyExceptionRenderer');
|
||||
ErrorHandler::handleFatalError(E_USER_ERROR, 'Initial error', __FILE__ ,__LINE__);
|
||||
}
|
||||
|
||||
/**
|
||||
* testExceptionRendererNestingProduction method
|
||||
*
|
||||
* @expectedException InternalErrorException
|
||||
* @return void
|
||||
*/
|
||||
public function testExceptionRendererNestingProduction() {
|
||||
Configure::write('debug', 0);
|
||||
Configure::write('Exception.renderer', 'FaultyExceptionRenderer');
|
||||
ErrorHandler::handleFatalError(E_USER_ERROR, 'Initial error', __FILE__ ,__LINE__);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue