Browse files

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
  • Loading branch information...
1 parent 201231c commit 18a34c03a4c73a865e2a92f24987b1bf1a9d41b0 @markstory markstory committed Nov 2, 2011
Showing with 39 additions and 11 deletions.
  1. +6 −7 lib/Cake/Error/ExceptionRenderer.php
  2. +33 −4 lib/Cake/Test/Case/Error/ExceptionRendererTest.php
View
13 lib/Cake/Error/ExceptionRenderer.php
@@ -119,12 +119,7 @@ public function __construct(Exception $exception) {
}
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 @@ public function error400($error) {
* @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
37 lib/Cake/Test/Case/Error/ExceptionRendererTest.php
@@ -287,10 +287,11 @@ public function testUnknownExceptionTypeWithExceptionThatHasA400Code() {
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 @@ public function testUnknownExceptionTypeWithNoCodeIsA500() {
$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 @@ public function testUnknownExceptionTypeWithCodeHigherThan500() {
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.');
}
/**

0 comments on commit 18a34c0

Please sign in to comment.