Adding some form of exception handling to front-end requests

This commit is contained in:
Dan Cryer 2014-05-09 12:04:42 +01:00
parent 5908e86fc0
commit b146af66b7
2 changed files with 19 additions and 1 deletions

View file

@ -10,6 +10,7 @@
namespace PHPCI;
use b8;
use b8\Exception\HttpException;
use b8\Http\Response;
use b8\Http\Response\RedirectResponse;
use b8\View;
@ -70,7 +71,15 @@ class Application extends b8\Application
*/
public function handleRequest()
{
$this->response = parent::handleRequest();
try {
$this->response = parent::handleRequest();
} catch (\Exception $ex) {
$this->config->set('page_title', 'Error');
$view = new View('exception');
$view->exception = $ex;
$this->response->setContent($view->render());
}
if (View::exists('layout') && $this->response->hasLayout()) {
$view = new View('layout');

View file

@ -0,0 +1,9 @@
<div class="panel panel-danger">
<div class="panel-heading">
<h2 class="panel-title">Sorry, there was a problem</h2>
</div>
<div class="panel-body">
<?php print $exception->getMessage(); ?>
</div>
</div>