/** * Render the error page based on an exception. * * @param object $error The exception for which to render the error page. * @return void */ public function render(Exception $error) { try { if (!$this->document) { // We're probably in an CLI environment exit($error->getMessage()); } $this->document->setType('error'); // Push the error object into the document $this->document->setError($error); if (ob_get_contents()) { ob_end_clean(); } $this->document->setTitle(\Lang::txt('Error') . ': ' . $error->getCode()); $path = PATH_APP . DS . 'templates'; if (!is_dir($path . DS . $this->template)) { $path = PATH_CORE . DS . 'templates'; } $data = $this->document->render(false, array('template' => $this->template, 'directory' => $path, 'debug' => $this->debug)); // Failsafe to get the error displayed. if (empty($data)) { exit($error->getMessage() . ' in ' . $error->getFile() . ':' . $error->getLine()); } else { $status = $error->getCode() ? $error->getCode() : 500; $status = $status < 100 || $status >= 600 ? 500 : $status; $response = new Response($data, $status); $response->send(); exit; } } catch (Exception $e) { $plain = new Plain($this->debug); $plain->render($e); } }
/** * Sends HTTP headers and content. * * @param boolean $flush * @return object Response */ public function send($flush = false) { if (!$this->getContent() && $this->original && $this->headers->get('Content-Type')) { $this->setContent($this->original); } return parent::send($flush); }