From ac932c4428fc35b08a629741cebaf8db3ee74975 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Rapha=C3=ABl=20Gertz?= Date: Wed, 24 Feb 2021 01:23:24 +0100 Subject: [PATCH] Fix error display --- Controller/ErrorController.php | 35 +++++++++++++++++++++++++++++++--- 1 file changed, 32 insertions(+), 3 deletions(-) diff --git a/Controller/ErrorController.php b/Controller/ErrorController.php index b9a3188..72e108f 100644 --- a/Controller/ErrorController.php +++ b/Controller/ErrorController.php @@ -18,7 +18,7 @@ class ErrorController extends DefaultController { /** * {@inheritdoc} */ - public function preview(Request $request, FlattenException $exception) { + public function show(Request $request, FlattenException $exception) { //Set section $section = $exception->getStatusCode().' '.$this->translator->trans($exception->getStatusText()); @@ -28,8 +28,37 @@ class ErrorController extends DefaultController { //Set the message $message = $exception->getMessage(); - //Set the trace - $trace = $exception->getAsString(); + //Init trace + $trace = null; + + //Prevent non admin access to trace + if ($this->isGranted('ROLE_ADMIN')) { + //Set project dir + $projectDir = $this->container->getParameter('kernel.project_dir').'/'; + + //Set the trace + //$trace = $exception->getAsString(); + $trace = ''; + + //Iterate on array + foreach($exception->toArray() as $current) { + $trace .= $current['class']; + + if (!empty($current['message'])) { + $trace .= ': '.$current['message']; + } + + if (!empty($current['trace'])) { + foreach($current['trace'] as $id => $sub) { + $trace .= "\n".'#'.$id.' '.$sub['class'].$sub['type'].$sub['function']; + if (!empty($sub['args'])) { + $trace .= '('.implode(', ', array_map(function($v){return $v[0].' '.$v[1];}, $sub['args'])).')'; + } + $trace .= ' in '.str_replace($projectDir, '', $sub['file']).':'.$sub['line']; + } + } + } + } //Render template return $this->render( -- 2.41.0