Skip to content

Commit 063fcf5

Browse files
committed
Moving error handler inclusion to before Configure::bootstrap() so app error handlers can be created.
Fixing issue where unknown exception types would not be handled spewing out errors. Unknown exception types are interpreted as 500 errors.
1 parent a8d4015 commit 063fcf5

File tree

3 files changed

+20
-2
lines changed

3 files changed

+20
-2
lines changed

cake/bootstrap.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@
3333
require LIBS . 'configure.php';
3434
require LIBS . 'set.php';
3535
require LIBS . 'cache.php';
36-
Configure::bootstrap();
3736
require LIBS . 'error_handler.php';
3837
set_exception_handler(array('ErrorHandler', 'handleException'));
38+
39+
Configure::bootstrap();
3940
require CAKE . 'dispatcher.php';

cake/libs/error_handler.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,9 @@ class ErrorHandler {
6262
public $error = null;
6363

6464
/**
65-
* Class constructor.
65+
* Creates the controller to perform rendering on the error response.
66+
* If the error is a CakeException it will be converted to either a 404 or a 500
67+
* type error depending on the code used to construct the error.
6668
*
6769
* @param string $method Method producing the error
6870
* @param array $messages Error messages
@@ -79,6 +81,8 @@ function __construct(Exception $exception) {
7981

8082
if ($exception instanceof CakeException && !in_array($method, get_class_methods($this))) {
8183
$method = '_cakeError';
84+
} elseif (!method_exists($this, $method)) {
85+
$method = 'error500';
8286
}
8387

8488
if ($method !== 'error' && Configure::read('debug') == 0) {

cake/tests/cases/libs/error_handler.test.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -330,6 +330,19 @@ function testErrorMethodCoercion() {
330330
$this->assertEquals($exception, $ErrorHandler->error);
331331
}
332332

333+
/**
334+
* test that unknown exception types are captured and converted to 500
335+
*
336+
* @return void
337+
*/
338+
function testUnknownExceptionType() {
339+
$exception = new MissingWidgetThingException('coding fail.');
340+
$ErrorHandler = new ErrorHandler($exception);
341+
342+
$this->assertFalse(method_exists($ErrorHandler, 'missingWidgetThing'), 'no method should exist.');
343+
$this->assertEquals('error500', $ErrorHandler->method, 'incorrect method coercion.');
344+
}
345+
333346
/**
334347
* testError method
335348
*

0 commit comments

Comments
 (0)