Fixing ExceptionRenderer so it can render exceptions that are subclasses

of CakeException that do not have custom templates, like ConfigureException.
Removing $lastError as it doesn't work.
Added tests.
This commit is contained in:
mark_story 2011-04-16 17:47:39 -04:00
parent c1a8dbbce7
commit a7a076dbee
2 changed files with 19 additions and 8 deletions

View file

@ -143,13 +143,10 @@ class ExceptionRenderer {
* @return Controller
*/
protected function _getController($exception) {
static $__previousError = null;
App::uses('CakeErrorController', 'Controller');
if ($__previousError != $exception) {
$__previousError = $exception;
try {
$controller = new CakeErrorController(Router::getRequest(false));
} else {
} catch (Exception $e) {
$controller = new Controller(Router::getRequest(false));
$controller->viewPath = 'errors';
}
@ -183,8 +180,12 @@ class ExceptionRenderer {
'name' => $error->getMessage(),
'error' => $error,
));
$this->controller->set($error->getAttributes());
$this->_outputMessage($this->template);
try {
$this->controller->set($error->getAttributes());
$this->_outputMessage($this->template);
} catch (Exception $e) {
$this->_outputMessage('error500');
}
}
/**
@ -234,4 +235,4 @@ class ExceptionRenderer {
$this->controller->afterFilter();
$this->controller->response->send();
}
}
}

View file

@ -574,6 +574,16 @@ class ExceptionRendererTest extends CakeTestCase {
'/Internal Error/'
),
500
),
array(
new CakeException('base class'),
array('/Internal Error/'),
500
),
array(
new ConfigureException('No file'),
array('/Internal Error/'),
500
)
);
}