Skip to content

Commit

Permalink
Moving error handler inclusion to before Configure::bootstrap() so ap…
Browse files Browse the repository at this point in the history
…p 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.
  • Loading branch information
markstory committed Sep 2, 2010
1 parent a8d4015 commit 063fcf5
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 2 deletions.
3 changes: 2 additions & 1 deletion cake/bootstrap.php
Expand Up @@ -33,7 +33,8 @@
require LIBS . 'configure.php';
require LIBS . 'set.php';
require LIBS . 'cache.php';
Configure::bootstrap();
require LIBS . 'error_handler.php';
set_exception_handler(array('ErrorHandler', 'handleException'));

Configure::bootstrap();
require CAKE . 'dispatcher.php';
6 changes: 5 additions & 1 deletion cake/libs/error_handler.php
Expand Up @@ -62,7 +62,9 @@ class ErrorHandler {
public $error = null;

/**
* Class constructor.
* 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.
*
* @param string $method Method producing the error
* @param array $messages Error messages
Expand All @@ -79,6 +81,8 @@ function __construct(Exception $exception) {

if ($exception instanceof CakeException && !in_array($method, get_class_methods($this))) {
$method = '_cakeError';
} elseif (!method_exists($this, $method)) {
$method = 'error500';
}

if ($method !== 'error' && Configure::read('debug') == 0) {
Expand Down
13 changes: 13 additions & 0 deletions cake/tests/cases/libs/error_handler.test.php
Expand Up @@ -330,6 +330,19 @@ function testErrorMethodCoercion() {
$this->assertEquals($exception, $ErrorHandler->error);
}

/**
* test that unknown exception types are captured and converted to 500
*
* @return void
*/
function testUnknownExceptionType() {
$exception = new MissingWidgetThingException('coding fail.');
$ErrorHandler = new ErrorHandler($exception);

$this->assertFalse(method_exists($ErrorHandler, 'missingWidgetThing'), 'no method should exist.');
$this->assertEquals('error500', $ErrorHandler->method, 'incorrect method coercion.');
}

/**
* testError method
*
Expand Down

0 comments on commit 063fcf5

Please sign in to comment.