From 18a34c03a4c73a865e2a92f24987b1bf1a9d41b0 Mon Sep 17 00:00:00 2001 From: mark_story Date: Wed, 2 Nov 2011 21:21:48 -0400 Subject: [PATCH] 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 --- lib/Cake/Error/ExceptionRenderer.php | 13 +++---- .../Test/Case/Error/ExceptionRendererTest.php | 37 +++++++++++++++++-- 2 files changed, 39 insertions(+), 11 deletions(-) diff --git a/lib/Cake/Error/ExceptionRenderer.php b/lib/Cake/Error/ExceptionRenderer.php index 58a410d26..758cc913d 100644 --- a/lib/Cake/Error/ExceptionRenderer.php +++ b/lib/Cake/Error/ExceptionRenderer.php @@ -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, )); diff --git a/lib/Cake/Test/Case/Error/ExceptionRendererTest.php b/lib/Cake/Test/Case/Error/ExceptionRendererTest.php index c45a07b56..48064925a 100644 --- a/lib/Cake/Test/Case/Error/ExceptionRendererTest.php +++ b/lib/Cake/Test/Case/Error/ExceptionRendererTest.php @@ -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.'); } /**