]> Raphaël G. Git Repositories - airbundle/commitdiff
Add error controller
authorRaphaël Gertz <git@rapsys.eu>
Wed, 11 Dec 2019 04:39:11 +0000 (05:39 +0100)
committerRaphaël Gertz <git@rapsys.eu>
Wed, 11 Dec 2019 04:46:49 +0000 (05:46 +0100)
Controller/ErrorController.php [new file with mode: 0644]
Resources/views/error.html.twig [new file with mode: 0644]

diff --git a/Controller/ErrorController.php b/Controller/ErrorController.php
new file mode 100644 (file)
index 0000000..eb53209
--- /dev/null
@@ -0,0 +1,40 @@
+<?php
+
+namespace Rapsys\AirBundle\Controller;
+
+use Symfony\Component\HttpFoundation\Request;
+use Symfony\Component\HttpFoundation\Response;
+#use Symfony\Component\Security\Core\Exception\AccessDeniedException;
+#use Symfony\Component\Security\Http\Authorization\AccessDeniedHandlerInterface;
+#use Symfony\Component\DependencyInjection\ContainerInterface;
+#use Symfony\Component\Routing\RouterInterface;
+#use Symfony\Component\Translation\TranslatorInterface;
+#use Twig\Environment;
+
+#use Symfony\Component\Debug\Exception\FlattenException;
+use Symfony\Component\ErrorHandler\Exception\FlattenException;
+
+class ErrorController extends DefaultController {
+       /**
+        * {@inheritdoc}
+        */
+       public function preview(Request $request, FlattenException $exception) {
+               //Set section
+               $section = $exception->getStatusCode().' '.$this->translator->trans($exception->getStatusText());
+
+               //Set title
+               $title = $section.' - '.$this->translator->trans($this->config['site']['title']);
+
+               //Set the message
+               $message = $exception->getMessage();
+
+               //Set the trace
+               $trace = $exception->getAsString();
+
+               //Render template
+               return $this->render(
+                       '@RapsysAir/error.html.twig',
+                       ['title' => $title, 'section' => $section, 'message' => $message, 'trace' => $trace]+$this->context
+               );
+       }
+}
diff --git a/Resources/views/error.html.twig b/Resources/views/error.html.twig
new file mode 100644 (file)
index 0000000..8dd4a69
--- /dev/null
@@ -0,0 +1,8 @@
+{% extends '@RapsysAir/body.html.twig' %}
+{% block content %}
+<section id="content">
+       <h2><a href="{{ path('rapsys_air') }}">{{ section }}</a></h2>
+       <p class="error">{% if message %}{{ message }}{% else %}{% trans %}Error{% endtrans %}{% endif %}</p>
+       {% if app.environment == 'dev' and trace is defined %}<pre class="trace">{{ trace }}</pre>{% endif %}
+</section>
+{% endblock %}