Skip to content

Commit

Permalink
Fixing issue where errors that did not have a 500+ code would use the…
Browse files Browse the repository at this point in the history
… incorrect status code.
  • Loading branch information
markstory committed Sep 4, 2010
1 parent 4d86361 commit d198230
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
7 changes: 4 additions & 3 deletions cake/libs/error_handler.php
Expand Up @@ -85,8 +85,8 @@ class ErrorHandler {

/**
* Creates the controller to perform rendering on the error response.
* If the error is a CakeException it will be converted to either a 404 or a 500
* type error depending on the code used to construct the error.
* If the error is a CakeException it will be converted to either a 400 or a 500
* code error depending on the code used to construct the error.
*
* @param string $method Method producing the error
* @param array $messages Error messages
Expand Down Expand Up @@ -228,7 +228,8 @@ public function error400($error) {
*/
public function error500($error) {
$url = Router::normalize($this->controller->request->here);
$this->controller->response->statusCode($error->getCode());
$code = ($error->getCode() > 500) ? $error->getCode() : 500;
$this->controller->response->statusCode($code);
$this->controller->set(array(
'name' => __('An Internal Error Has Occurred'),
'message' => h($url),
Expand Down
12 changes: 12 additions & 0 deletions cake/tests/cases/libs/error_handler.test.php
Expand Up @@ -341,6 +341,12 @@ function testErrorMethodCoercion() {
function testUnknownExceptionTypeWithExceptionThatHasA400Code() {
$exception = new MissingWidgetThingException('coding fail.');
$ErrorHandler = new ErrorHandler($exception);
$ErrorHandler->controller->response = $this->getMock('CakeResponse', array('statusCode'));
$ErrorHandler->controller->response->expects($this->once())->method('statusCode')->with(404);

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

$this->assertFalse(method_exists($ErrorHandler, 'missingWidgetThing'), 'no method should exist.');
$this->assertEquals('error400', $ErrorHandler->method, 'incorrect method coercion.');
Expand All @@ -354,6 +360,12 @@ function testUnknownExceptionTypeWithExceptionThatHasA400Code() {
function testUnknownExceptionTypeWithNoCodeIsA500() {
$exception = new OutOfBoundsException('foul ball.');
$ErrorHandler = new ErrorHandler($exception);
$ErrorHandler->controller->response = $this->getMock('CakeResponse', array('statusCode'));
$ErrorHandler->controller->response->expects($this->once())->method('statusCode')->with(500);

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

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

0 comments on commit d198230

Please sign in to comment.