Skip to content
Permalink
Browse files

Moving error handler inclusion to before Configure::bootstrap() so ap…

…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 063fcf557d31b6e5af382b367f96257d5b89a973
Showing with 20 additions and 2 deletions.
  1. +2 −1 cake/bootstrap.php
  2. +5 −1 cake/libs/error_handler.php
  3. +13 −0 cake/tests/cases/libs/error_handler.test.php
@@ -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';
@@ -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
@@ -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) {
@@ -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
*

0 comments on commit 063fcf5

Please sign in to comment.
You can’t perform that action at this time.