From 40e219622a2c416ab36cb39b26a5e1354e4438cc Mon Sep 17 00:00:00 2001 From: Jeremy Benoist Date: Sat, 1 Oct 2016 14:51:54 +0200 Subject: Customize errors templates All error goes to the same template which only display the error message and the status code. --- .../CoreBundle/Controller/ExceptionController.php | 40 ++++++++++++++++++++++ .../ParamConverter/UsernameRssTokenConverter.php | 7 ++-- .../CoreBundle/Resources/config/services.yml | 6 ++++ .../views/themes/baggy/Exception/error.html.twig | 24 +++++++++++++ .../themes/material/Exception/error.html.twig | 30 ++++++++++++++++ 5 files changed, 103 insertions(+), 4 deletions(-) create mode 100644 src/Wallabag/CoreBundle/Controller/ExceptionController.php create mode 100644 src/Wallabag/CoreBundle/Resources/views/themes/baggy/Exception/error.html.twig create mode 100644 src/Wallabag/CoreBundle/Resources/views/themes/material/Exception/error.html.twig (limited to 'src/Wallabag/CoreBundle') diff --git a/src/Wallabag/CoreBundle/Controller/ExceptionController.php b/src/Wallabag/CoreBundle/Controller/ExceptionController.php new file mode 100644 index 00000000..abfa9c2f --- /dev/null +++ b/src/Wallabag/CoreBundle/Controller/ExceptionController.php @@ -0,0 +1,40 @@ +templateExists($template)) { + return $template; + } + } + + // try to find a template for the given format + $template = sprintf('@Twig/Exception/%s.%s.twig', $name, $format); + if ($this->templateExists($template)) { + return $template; + } + + // default to a generic HTML exception + $request->setRequestFormat('html'); + + return sprintf('@Twig/Exception/%s.html.twig', $showException ? 'exception_full' : $name); + } +} diff --git a/src/Wallabag/CoreBundle/ParamConverter/UsernameRssTokenConverter.php b/src/Wallabag/CoreBundle/ParamConverter/UsernameRssTokenConverter.php index 6ea2a4f3..40b5673d 100644 --- a/src/Wallabag/CoreBundle/ParamConverter/UsernameRssTokenConverter.php +++ b/src/Wallabag/CoreBundle/ParamConverter/UsernameRssTokenConverter.php @@ -49,7 +49,7 @@ class UsernameRssTokenConverter implements ParamConverterInterface $em = $this->registry->getManagerForClass($configuration->getClass()); // Check, if class name is what we need - if ('Wallabag\UserBundle\Entity\User' !== $em->getClassMetadata($configuration->getClass())->getName()) { + if (null !== $em && 'Wallabag\UserBundle\Entity\User' !== $em->getClassMetadata($configuration->getClass())->getName()) { return false; } @@ -69,9 +69,8 @@ class UsernameRssTokenConverter implements ParamConverterInterface $username = $request->attributes->get('username'); $rssToken = $request->attributes->get('token'); - // Check, if route attributes exists - if (null === $username || null === $rssToken) { - throw new \InvalidArgumentException('Route attribute is missing'); + if (!$request->attributes->has('username') || !$request->attributes->has('token')) { + return false; } // Get actual entity manager for class diff --git a/src/Wallabag/CoreBundle/Resources/config/services.yml b/src/Wallabag/CoreBundle/Resources/config/services.yml index 23e6d3ca..a769b07e 100644 --- a/src/Wallabag/CoreBundle/Resources/config/services.yml +++ b/src/Wallabag/CoreBundle/Resources/config/services.yml @@ -133,3 +133,9 @@ services: host: '%redis_host%' port: '%redis_port%' schema: tcp + + wallabag_core.exception_controller: + class: Wallabag\CoreBundle\Controller\ExceptionController + arguments: + - '@twig' + - '%kernel.debug%' diff --git a/src/Wallabag/CoreBundle/Resources/views/themes/baggy/Exception/error.html.twig b/src/Wallabag/CoreBundle/Resources/views/themes/baggy/Exception/error.html.twig new file mode 100644 index 00000000..b52634fd --- /dev/null +++ b/src/Wallabag/CoreBundle/Resources/views/themes/baggy/Exception/error.html.twig @@ -0,0 +1,24 @@ +{% extends "WallabagCoreBundle::layout.html.twig" %} + +{% block title %}{{ 'error.page_title'|trans }}{% endblock %} + +{% block body_class %}login{% endblock %} + +{% block menu %}{% endblock %} +{% block messages %}{% endblock %} +{% block header %}{% endblock %} + +{% block content %} +
+
+
+
wallabag logo
+

{{ status_code }}: {{ status_text }}

+

{{ exception.message }}

+
+
+
+{% endblock %} + +{% block footer %} +{% endblock %} diff --git a/src/Wallabag/CoreBundle/Resources/views/themes/material/Exception/error.html.twig b/src/Wallabag/CoreBundle/Resources/views/themes/material/Exception/error.html.twig new file mode 100644 index 00000000..6be78edb --- /dev/null +++ b/src/Wallabag/CoreBundle/Resources/views/themes/material/Exception/error.html.twig @@ -0,0 +1,30 @@ +{% extends "WallabagCoreBundle::layout.html.twig" %} + +{% block title %}{{ 'error.page_title'|trans }}{% endblock %} + +{% block body_class %}login{% endblock %} + +{% block menu %}{% endblock %} +{% block messages %}{% endblock %} + +{% block content %} +
+
+
+
wallabag logo
+
+
+
{{ status_code }}: {{ status_text }}
+

{{ exception.message }}

+ {# {% for trace in exception.trace %} +

{{ trace.class }} - {{ trace.type }} - {{ trace.file }} - {{ trace.line }}

+ {% endfor %} #} +
+
+
+
+
+{% endblock %} + +{% block footer %} +{% endblock %} -- cgit v1.2.3