From a0f5177533de67d619b9fb29e5a66f93ec692fc5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20B=C3=B6hmer?= Date: Sat, 30 May 2020 20:48:08 +0200 Subject: [PATCH] Added custom error pages, that assists users with common problems. --- config/packages/twig.yaml | 2 + config/parameters.yaml | 6 ++ .../Exception/assets/error.css.twig | 95 +++++++++++++++++++ .../TwigBundle/Exception/error.html.twig | 53 +++++++++++ .../TwigBundle/Exception/error403.html.twig | 6 ++ .../TwigBundle/Exception/error404.html.twig | 5 + .../TwigBundle/Exception/error500.html.twig | 35 +++++++ 7 files changed, 202 insertions(+) create mode 100644 templates/bundles/TwigBundle/Exception/assets/error.css.twig create mode 100644 templates/bundles/TwigBundle/Exception/error.html.twig create mode 100644 templates/bundles/TwigBundle/Exception/error403.html.twig create mode 100644 templates/bundles/TwigBundle/Exception/error404.html.twig create mode 100644 templates/bundles/TwigBundle/Exception/error500.html.twig diff --git a/config/packages/twig.yaml b/config/packages/twig.yaml index 8b93acfb..4995106c 100644 --- a/config/packages/twig.yaml +++ b/config/packages/twig.yaml @@ -13,3 +13,5 @@ twig: locale_menu: '%partdb.locale_menu%' attachment_manager: '@App\Services\Attachments\AttachmentManager' label_profile_dropdown_helper: '@App\Services\LabelSystem\LabelProfileDropdownHelper' + error_page_admin_email: '%partdb.error_pages.admin_email%' + error_page_show_help: '%partdb.error_pages.show_help%' diff --git a/config/parameters.yaml b/config/parameters.yaml index e038203b..ec9128a7 100644 --- a/config/parameters.yaml +++ b/config/parameters.yaml @@ -33,6 +33,12 @@ parameters: partdb.attachments.dir.media: 'public/media/' # The folder where uploaded attachment files are saved (must be in public folder) partdb.attachments.dir.secure: 'uploads/' # The folder where secured attachment files are saved (must not be in public/) + ###################################################################################################################### + # Error pages + ###################################################################################################################### + partdb.error_pages.admin_email: '' # You can set an email address here, which is shown on an error page, how to contact an administrator + partdb.error_pages.show_help: false # If this is set to true, solutions to common problems are shown on error pages. Disable this, if you do not want your users to see them... + ###################################################################################################################### # Miscellaneous ###################################################################################################################### diff --git a/templates/bundles/TwigBundle/Exception/assets/error.css.twig b/templates/bundles/TwigBundle/Exception/assets/error.css.twig new file mode 100644 index 00000000..0d0a1be6 --- /dev/null +++ b/templates/bundles/TwigBundle/Exception/assets/error.css.twig @@ -0,0 +1,95 @@ +body { + background-color: #fff; + color: #222; + font: 16px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif; + margin: 0; +} +.container { + padding: 50px; + width: 100%; + box-sizing: border-box; +} + +h1 { + margin-top: 10px; + color: #dc3545; + font-size: 24px; +} +h2 { + font-size: 18px; +} + +.status_code { + text-align: center; + + font-size: 72px; + line-height: 0.5; +} + +.status_text { + text-align: center; + line-height: 0.5; + font-size: 32px; +} + +.status_comment { + text-align: center; + line-height: 1; +} + +.help_text { + text-align: center; + font-size: 18px; +} + +.text-muted { + color: #6c757d!important; +} + +.text-center { + text-align: center; +} + +ul { + display: table; + margin: 10px auto; + line-height: 1.4; + text-align: left; +} + +.footer { + box-sizing: border-box; + position: absolute; + bottom: 0; + width: 100%; + height: 60px; + line-height: 1.2; + text-align: left; + padding-top: 15px; + padding-left: 30px; + background-color: #f5f5f5; +} + +.dev_hint { + margin-top: 45px; + line-height: 0.5; + text-align: center; +} + +code { + font-size: 87.5%; + color: #e83e8c; + word-break: break-word; +} + +code, kbd, pre, samp { + font-family: SFMono-Regular,Menlo,Monaco,Consolas,"Liberation Mono","Courier New",monospace; +} + +kbd { + padding: .2rem .4rem; + font-size: 87.5%; + color: #fff; + background-color: #212529; + border-radius: .2rem; +} \ No newline at end of file diff --git a/templates/bundles/TwigBundle/Exception/error.html.twig b/templates/bundles/TwigBundle/Exception/error.html.twig new file mode 100644 index 00000000..ea9b5849 --- /dev/null +++ b/templates/bundles/TwigBundle/Exception/error.html.twig @@ -0,0 +1,53 @@ + + + + + + + An Error Occurred: {{ status_text }} + + + +
+ +

{% block status_code %}{{ status_code }}{% endblock %}

+

{% block status_text %}{{ status_text }}{% endblock %}

+

+ {% block status_comment %} + Consider yourself lucky. You found some rare error code.
You should maybe inform your administrator about it... + {% endblock %} +

+ {% block further_actions %}

You can try to Go Back or Visit the homepage.

{% endblock %} + {% block admin_contact %}

If this error persists, please contact your + {% if error_page_admin_email is not empty %} + administrator. + {% else %} + administrator. + {% endif %} +

+ {% endblock %} + + {% if error_page_show_help %} +
+ Infos for Admin: + {% block admin_info %} + You could try to do following things, if this error is unexpected: +
    +
  • Check var/log/prod.log for additional informations
  • +
  • Run php bin/console cache:clear to clear cache
  • +
+ {% endblock %} +

If you think that this is an error in Part-DB, open an Issue on GitHub.

+

You can disable these hints in config/parameters.yaml by setting partdb.error_pages.show_help to false.

+
+ {% endif %} + +
+ + + + \ No newline at end of file diff --git a/templates/bundles/TwigBundle/Exception/error403.html.twig b/templates/bundles/TwigBundle/Exception/error403.html.twig new file mode 100644 index 00000000..f5987179 --- /dev/null +++ b/templates/bundles/TwigBundle/Exception/error403.html.twig @@ -0,0 +1,6 @@ +{% extends "bundles/TwigBundle/Exception/error.html.twig" %} + +{% block status_comment %} + Nice try! But you are not allowed to do this! +
If you think you should have access to this ressource, contact the adminstrator. +{% endblock %} \ No newline at end of file diff --git a/templates/bundles/TwigBundle/Exception/error404.html.twig b/templates/bundles/TwigBundle/Exception/error404.html.twig new file mode 100644 index 00000000..b2d79417 --- /dev/null +++ b/templates/bundles/TwigBundle/Exception/error404.html.twig @@ -0,0 +1,5 @@ +{% extends "bundles/TwigBundle/Exception/error.html.twig" %} + +{% block status_comment %} + This page (or element) does not exist. Please check your URL. +{% endblock %} \ No newline at end of file diff --git a/templates/bundles/TwigBundle/Exception/error500.html.twig b/templates/bundles/TwigBundle/Exception/error500.html.twig new file mode 100644 index 00000000..f28933be --- /dev/null +++ b/templates/bundles/TwigBundle/Exception/error500.html.twig @@ -0,0 +1,35 @@ +{% extends "bundles/TwigBundle/Exception/error.html.twig" %} + +{% block status_comment %} + Something bad happened internally. +
There is nothing you could do about this, except trying to reload the page. +{% endblock %} + +{% block admin_info %} + {% if exception.class == "Doctrine\\DBAL\\Exception\\ConnectionException" %} + Can not connect to database. Try follwing things: + + {% elseif exception.class == "Twig\\Error\\RuntimeError" and 'manifest.json' in exception.message %} + Can not load frontend assets. Try following things: + + {% elseif exception.class == "Doctrine\\DBAL\\Exception\\InvalidFieldNameException" %} + Invalid database schema. Try following things: + + {% else %} + You could try following things, if this error is unexpected: + + {% endif %} +{% endblock %} \ No newline at end of file