From 466e57ee70f0708a2684f5830410053770a27e85 Mon Sep 17 00:00:00 2001 From: Adirelle Date: Fri, 15 May 2015 16:44:38 +0200 Subject: [PATCH 1/2] Application::handleRequest now properly displays exceptions. --- PHPCI/Application.php | 21 +++++++-------------- 1 file changed, 7 insertions(+), 14 deletions(-) diff --git a/PHPCI/Application.php b/PHPCI/Application.php index 8dcdf76d7..cfed796b9 100644 --- a/PHPCI/Application.php +++ b/PHPCI/Application.php @@ -86,31 +86,24 @@ public function handleRequest() { try { $this->response = parent::handleRequest(); - } catch (HttpException $ex) { - $this->config->set('page_title', 'Error'); - $view = new View('exception'); - $view->exception = $ex; + if ($this->response->hasLayout() && $this->controller->layout) { + $this->setLayoutVariables($this->controller->layout); + + $this->controller->layout->content = $this->response->getContent(); + $this->response->setContent($this->controller->layout->render()); + } - $this->response->setResponseCode($ex->getErrorCode()); - $this->response->setContent($view->render()); } catch (\Exception $ex) { $this->config->set('page_title', 'Error'); $view = new View('exception'); $view->exception = $ex; - $this->response->setResponseCode(500); + $this->response->setResponseCode($ex instanceof HttpException ? $ex->getErrorCode() : 500); $this->response->setContent($view->render()); } - if ($this->response->hasLayout() && $this->controller->layout) { - $this->setLayoutVariables($this->controller->layout); - - $this->controller->layout->content = $this->response->getContent(); - $this->response->setContent($this->controller->layout->render()); - } - return $this->response; } From 5dd8bdec23cef6b4a852bfd54b70f8f992fb6128 Mon Sep 17 00:00:00 2001 From: Adirelle Date: Sat, 16 May 2015 17:59:28 +0200 Subject: [PATCH 2/2] Application::handleRequest: avoid the instanceof test. --- PHPCI/Application.php | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/PHPCI/Application.php b/PHPCI/Application.php index cfed796b9..2a793b81a 100644 --- a/PHPCI/Application.php +++ b/PHPCI/Application.php @@ -94,15 +94,21 @@ public function handleRequest() $this->response->setContent($this->controller->layout->render()); } + return $this->response; + + } catch (\HttpException $ex) { + $this->response->setResponseCode($ex->getErrorCode()); } catch (\Exception $ex) { - $this->config->set('page_title', 'Error'); + $this->response->setResponseCode(500); + } - $view = new View('exception'); - $view->exception = $ex; + // We only get there if an excetion has been caught + $this->config->set('page_title', 'Error'); - $this->response->setResponseCode($ex instanceof HttpException ? $ex->getErrorCode() : 500); - $this->response->setContent($view->render()); - } + $view = new View('exception'); + $view->exception = $ex; + + $this->response->setContent($view->render()); return $this->response; }