/** * Set the body for error conditions * * @param \Exception $exception The Exception object * * @return void * * @since 1.0 */ private function setErrorOutput(\Exception $exception) { switch (strtolower($this->input->getWord('format', 'html'))) { case 'json': $data = ['code' => $exception->getCode(), 'message' => $exception->getMessage(), 'error' => true]; $body = json_encode($data); break; case 'html': default: // Need the default controller in order to fetch the renderer $controller = (new DefaultController($this->input, $this))->setContainer($this->getContainer()); // Build a default view object and render with the exception layout $controller->initializeRenderer(); $view = new DefaultHtmlView(new DefaultModel($this->getContainer()->get('db')), $this->getContainer()->get('renderer')); $body = $view->setLayout('exception')->setData(['exception' => $exception])->render(); break; } $this->setBody($body); }