Fixing issue where errors containing code = 500, were not actually converted to error500 when debug = 0. Making missingConnection, and missingTable into error500 errors.

This commit is contained in:
Mark Story 2010-09-06 16:46:41 -04:00
parent b491414a51
commit c60edfae6d
4 changed files with 24 additions and 4 deletions

View file

@ -106,6 +106,7 @@ class ErrorHandler extends Object {
if (!in_array(strtolower($method), array_map('strtolower', get_class_methods($this)))) {
$method = 'error';
}
if ($method !== 'error') {
if (Configure::read('debug') == 0) {
$parentClass = get_parent_class($this);
@ -116,7 +117,7 @@ class ErrorHandler extends Object {
if (in_array(strtolower($method), $parentMethods)) {
$method = 'error404';
}
if (isset($code) && $code == 500) {
if (isset($messages[0]['code']) && $messages[0]['code'] == 500) {
$method = 'error500';
}
}

View file

@ -239,7 +239,7 @@ class ConnectionManager extends Object {
$this->_connectionsEnum[$name] = $this->__connectionData($config);
}
} else {
$this->cakeError('missingConnection', array(array('className' => 'ConnectionManager')));
$this->cakeError('missingConnection', array(array('code' => 500, 'className' => 'ConnectionManager')));
}
}

View file

@ -769,7 +769,8 @@ class Model extends Overloadable {
if (is_array($sources) && !in_array(strtolower($this->tablePrefix . $tableName), array_map('strtolower', $sources))) {
return $this->cakeError('missingTable', array(array(
'className' => $this->alias,
'table' => $this->tablePrefix . $tableName
'table' => $this->tablePrefix . $tableName,
'code' => 500
)));
}
$this->_schema = null;
@ -2826,7 +2827,7 @@ class Model extends Overloadable {
}
if (empty($db) || !is_object($db)) {
return $this->cakeError('missingConnection', array(array('className' => $this->alias)));
return $this->cakeError('missingConnection', array(array('code' => 500, 'className' => $this->alias)));
}
}

View file

@ -609,4 +609,22 @@ class ErrorHandlerTest extends CakeTestCase {
$this->assertPattern('/<em>Article<\/em> could not be found./', $result);
$this->assertPattern('/(\/|\\\)article.php/', $result);
}
/**
* testing that having a code => 500 in the cakeError call makes an
* internal server error.
*
* @return void
*/
function testThatCode500Works() {
Configure::write('debug', 0);
ob_start();
$TestErrorHandler = new TestErrorHandler('missingTable', array(
'className' => 'Article',
'table' => 'articles',
'code' => 500
));
$result = ob_get_clean();
$this->assertPattern('/<h2>An Internal Error Has Occurred<\/h2>/', $result);
}
}