mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-01-19 02:56:15 +00:00
Fix issue where unknown exceptions would be squashed.
Fix issue where unknown exceptions with error codes that were not in HTTP ranges would be ignored. In development those messages should display. Fixes #2205
This commit is contained in:
parent
201231cd42
commit
18a34c03a4
2 changed files with 39 additions and 11 deletions
|
@ -119,12 +119,7 @@ class ExceptionRenderer {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Configure::read('debug') == 0) {
|
if (Configure::read('debug') == 0) {
|
||||||
$parentClass = get_parent_class($this);
|
if ($method == '_cakeError') {
|
||||||
if ($parentClass != __CLASS__) {
|
|
||||||
$method = 'error400';
|
|
||||||
}
|
|
||||||
$parentMethods = (array)get_class_methods($parentClass);
|
|
||||||
if (in_array($method, $parentMethods)) {
|
|
||||||
$method = 'error400';
|
$method = 'error400';
|
||||||
}
|
}
|
||||||
if ($code == 500) {
|
if ($code == 500) {
|
||||||
|
@ -223,11 +218,15 @@ class ExceptionRenderer {
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function error500($error) {
|
public function error500($error) {
|
||||||
|
$message = $error->getMessage();
|
||||||
|
if (Configure::read('debug') == 0) {
|
||||||
|
$message = __d('cake', 'An Internal Error Has Occurred');
|
||||||
|
}
|
||||||
$url = $this->controller->request->here();
|
$url = $this->controller->request->here();
|
||||||
$code = ($error->getCode() > 500 && $error->getCode() < 506) ? $error->getCode() : 500;
|
$code = ($error->getCode() > 500 && $error->getCode() < 506) ? $error->getCode() : 500;
|
||||||
$this->controller->response->statusCode($code);
|
$this->controller->response->statusCode($code);
|
||||||
$this->controller->set(array(
|
$this->controller->set(array(
|
||||||
'name' => __d('cake', 'An Internal Error Has Occurred'),
|
'name' => $message,
|
||||||
'message' => h($url),
|
'message' => h($url),
|
||||||
'error' => $error,
|
'error' => $error,
|
||||||
));
|
));
|
||||||
|
|
|
@ -287,10 +287,11 @@ class ExceptionRendererTest extends CakeTestCase {
|
||||||
|
|
||||||
ob_start();
|
ob_start();
|
||||||
$ExceptionRenderer->render();
|
$ExceptionRenderer->render();
|
||||||
$results = ob_get_clean();
|
$result = ob_get_clean();
|
||||||
|
|
||||||
$this->assertFalse(method_exists($ExceptionRenderer, 'missingWidgetThing'), 'no method should exist.');
|
$this->assertFalse(method_exists($ExceptionRenderer, 'missingWidgetThing'), 'no method should exist.');
|
||||||
$this->assertEquals('error400', $ExceptionRenderer->method, 'incorrect method coercion.');
|
$this->assertEquals('error400', $ExceptionRenderer->method, 'incorrect method coercion.');
|
||||||
|
$this->assertContains('coding fail', $result, 'Text should show up.');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -302,13 +303,40 @@ class ExceptionRendererTest extends CakeTestCase {
|
||||||
$exception = new OutOfBoundsException('foul ball.');
|
$exception = new OutOfBoundsException('foul ball.');
|
||||||
$ExceptionRenderer = new ExceptionRenderer($exception);
|
$ExceptionRenderer = new ExceptionRenderer($exception);
|
||||||
$ExceptionRenderer->controller->response = $this->getMock('CakeResponse', array('statusCode', '_sendHeader'));
|
$ExceptionRenderer->controller->response = $this->getMock('CakeResponse', array('statusCode', '_sendHeader'));
|
||||||
$ExceptionRenderer->controller->response->expects($this->once())->method('statusCode')->with(500);
|
$ExceptionRenderer->controller->response->expects($this->once())
|
||||||
|
->method('statusCode')
|
||||||
|
->with(500);
|
||||||
|
|
||||||
ob_start();
|
ob_start();
|
||||||
$ExceptionRenderer->render();
|
$ExceptionRenderer->render();
|
||||||
$results = ob_get_clean();
|
$result = ob_get_clean();
|
||||||
|
|
||||||
$this->assertEquals('error500', $ExceptionRenderer->method, 'incorrect method coercion.');
|
$this->assertEquals('error500', $ExceptionRenderer->method, 'incorrect method coercion.');
|
||||||
|
$this->assertContains('foul ball.', $result, 'Text should show up as its debug mode.');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* test that unknown exceptions have messages ignored.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function testUnknownExceptionInProduction() {
|
||||||
|
Configure::write('debug', 0);
|
||||||
|
|
||||||
|
$exception = new OutOfBoundsException('foul ball.');
|
||||||
|
$ExceptionRenderer = new ExceptionRenderer($exception);
|
||||||
|
$ExceptionRenderer->controller->response = $this->getMock('CakeResponse', array('statusCode', '_sendHeader'));
|
||||||
|
$ExceptionRenderer->controller->response->expects($this->once())
|
||||||
|
->method('statusCode')
|
||||||
|
->with(500);
|
||||||
|
|
||||||
|
ob_start();
|
||||||
|
$ExceptionRenderer->render();
|
||||||
|
$result = ob_get_clean();
|
||||||
|
|
||||||
|
$this->assertEquals('error500', $ExceptionRenderer->method, 'incorrect method coercion.');
|
||||||
|
$this->assertNotContains('foul ball.', $result, 'Text should no show up.');
|
||||||
|
$this->assertContains('Internal Error', $result, 'Generic message only.');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -324,9 +352,10 @@ class ExceptionRendererTest extends CakeTestCase {
|
||||||
|
|
||||||
ob_start();
|
ob_start();
|
||||||
$ExceptionRenderer->render();
|
$ExceptionRenderer->render();
|
||||||
$results = ob_get_clean();
|
$result = ob_get_clean();
|
||||||
|
|
||||||
$this->assertEquals('error500', $ExceptionRenderer->method, 'incorrect method coercion.');
|
$this->assertEquals('error500', $ExceptionRenderer->method, 'incorrect method coercion.');
|
||||||
|
$this->assertContains('foul ball.', $result, 'Text should show up as its debug mode.');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Add table
Reference in a new issue