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:
mark_story 2011-11-02 21:21:48 -04:00
parent 201231cd42
commit 18a34c03a4
2 changed files with 39 additions and 11 deletions

View file

@ -119,12 +119,7 @@ class ExceptionRenderer {
}
if (Configure::read('debug') == 0) {
$parentClass = get_parent_class($this);
if ($parentClass != __CLASS__) {
$method = 'error400';
}
$parentMethods = (array)get_class_methods($parentClass);
if (in_array($method, $parentMethods)) {
if ($method == '_cakeError') {
$method = 'error400';
}
if ($code == 500) {
@ -223,11 +218,15 @@ class ExceptionRenderer {
* @return void
*/
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();
$code = ($error->getCode() > 500 && $error->getCode() < 506) ? $error->getCode() : 500;
$this->controller->response->statusCode($code);
$this->controller->set(array(
'name' => __d('cake', 'An Internal Error Has Occurred'),
'name' => $message,
'message' => h($url),
'error' => $error,
));

View file

@ -287,10 +287,11 @@ class ExceptionRendererTest extends CakeTestCase {
ob_start();
$ExceptionRenderer->render();
$results = ob_get_clean();
$result = ob_get_clean();
$this->assertFalse(method_exists($ExceptionRenderer, 'missingWidgetThing'), 'no method should exist.');
$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.');
$ExceptionRenderer = new ExceptionRenderer($exception);
$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();
$ExceptionRenderer->render();
$results = ob_get_clean();
$result = ob_get_clean();
$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();
$ExceptionRenderer->render();
$results = ob_get_clean();
$result = ob_get_clean();
$this->assertEquals('error500', $ExceptionRenderer->method, 'incorrect method coercion.');
$this->assertContains('foul ball.', $result, 'Text should show up as its debug mode.');
}
/**