/** * create response * with a HttpException status code and headers are considered * other exceptions default to status code 500 * a error_docs/error_{status_code}.php template is parsed, when found * otherwise the exception data is decorated and dumped * * @param \Exception $e * @return \vxPHP\Http\Response */ protected function createResponse(\Exception $e) { if ($e instanceof HttpException) { $status = $e->getStatusCode(); $headers = $e->getHeaders(); } else { $status = Response::HTTP_INTERNAL_SERVER_ERROR; $headers = array(); } $config = Application::getInstance()->getConfig(); if (isset($config->paths['tpl_path'])) { $path = ($config->paths['tpl_path']['absolute'] ? '' : rtrim(Application::getInstance()->getRootPath(), DIRECTORY_SEPARATOR)) . $config->paths['tpl_path']['subdir']; if (file_exists($path . 'error_docs' . DIRECTORY_SEPARATOR . 'error_' . $status . '.php')) { $tpl = SimpleTemplate::create('error_docs' . DIRECTORY_SEPARATOR . 'error_' . $status . '.php'); $content = $tpl->assign('exception', $e)->assign('status', $status)->display(); } else { $content = $this->decorateException($e, $status); } } else { $content = $this->decorateException($e, $status); } return new Response($content, $status, $headers); }