/** * Return a response to send using an exception. * * @param MerciKIException e The thrown exception. * @return The response to send. */ protected function _catchException(MerciKIException $e) { $code = $e->getCode(); if ($code == null) { $code = 500; } try { $view = new View(); $view->addVars(['message' => $e->getMessage(), 'code' => $code]); $content = $view->content('Views' . DS . 'Exception' . DS . $e->getViewFileName() . '.php', 'content'); if ($e->getLayoutFileName()) { $content = $view->content('Views' . DS . 'Layout' . DS . $e->getLayoutFileName() . '.php'); } } catch (ViewNotExist $v) { $content = '<!DOCTYPE html><html><head><title>ERROR</title></head><body>' . 'No view found for this exception : ' . $code . ' - ' . $e->getMessage() . '</body></html>'; } catch (MerciKIException $m) { return $this->_catchException($m); } return new HtmlResponse($content, $code); }