Skip to content

Commit

Permalink
Making unknown errors with codes higher than 500 render as error500.
Browse files Browse the repository at this point in the history
Test added.
  • Loading branch information
markstory committed Dec 11, 2010
1 parent 504b4d4 commit 60ada44
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
2 changes: 1 addition & 1 deletion cake/libs/error/exception_renderer.php
Expand Up @@ -107,7 +107,7 @@ function __construct(Exception $exception) {
}
} elseif (!$methodExists) {
$method = 'error500';
if ($code >= 400) {
if ($code >= 400 && $code < 500) {
$method = 'error400';
}
}
Expand Down
18 changes: 18 additions & 0 deletions cake/tests/cases/libs/error/exception_renderer.test.php
Expand Up @@ -322,6 +322,24 @@ function testUnknownExceptionTypeWithNoCodeIsA500() {
$this->assertEquals('error500', $ExceptionRenderer->method, 'incorrect method coercion.');
}

/**
* test that unknown exception types with valid status codes are treated correctly.
*
* @return void
*/
function testUnknownExceptionTypeWithCodeHigherThan500() {
$exception = new OutOfBoundsException('foul ball.', 501);
$ExceptionRenderer = new ExceptionRenderer($exception);
$ExceptionRenderer->controller->response = $this->getMock('CakeResponse', array('statusCode', '_sendHeader'));
$ExceptionRenderer->controller->response->expects($this->once())->method('statusCode')->with(501);

ob_start();
$ExceptionRenderer->render();
$results = ob_get_clean();

$this->assertEquals('error500', $ExceptionRenderer->method, 'incorrect method coercion.');
}

/**
* testerror400 method
*
Expand Down

0 comments on commit 60ada44

Please sign in to comment.