public function onKernelException(GetResponseForExceptionEvent $event)
{
$exception = $event->getException();
if ($this->env != "prod") {
$event->setException($exception);
return;
}
try {
$code = 404;
if ($exception instanceof \Symfony\Component\HttpKernel\Exception\NotFoundHttpException) {
$code = 404;
} else {
if ($exception instanceof \Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException) {
$code = 403;
}
}
$file = $code;
if ($this->env != "prod") {
//$file = $file . '.' . $this->env;
}
$file = $file . '.html.twig';
$template = $this->siteManager->getTemplate("portal");
$template = "SymbbTemplateDefaultBundle:Exception:" . $file;
$response = new Response($this->templating->render($template, array('status_code' => $code, 'status_text' => $exception->getMessage(), 'exception' => $exception)));
// setup the Response object based on the caught exception
$event->setResponse($response);
} catch (\Exception $exc) {
$event->setException($exception);
}
// you can alternatively set a new Exception
// $exception = new \Exception('Some special exception');
// $event->setException($exception);
}