├── .gitignore ├── CHANGELOG.md ├── LICENSE ├── README.md ├── composer.json └── src ├── Resources ├── doc │ └── images │ │ └── webfactory_exceptions_standardExceptionPage-example.png ├── translations │ ├── webfactory-exceptions-bundle.de.yml │ ├── webfactory-exceptions-bundle.en.yml │ ├── webfactory-exceptions-bundle.fr.yml │ ├── webfactory-exceptions-bundle.hr.yml │ └── webfactory-exceptions-bundle.it.yml └── views │ └── Exception │ └── blocks.html.twig └── WebfactoryExceptionsBundle.php /.gitignore: -------------------------------------------------------------------------------- 1 | vendor/ 2 | phpunit.xml 3 | composer.lock 4 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Upgrading notes 2 | 3 | We're trying to follow [SemVer](http://semver.org) principles to the best of our abilities and also to release versions as often as possible. 4 | 5 | This document tries to point out the things you ought to keep in mind when trying to newer versions. 6 | 7 | ## 5.0.0 8 | 9 | * Removed the custom controller logic that could be used to preview error pages. This code has become part of the Symfony Core in 2.6, so it was no longer necessary for a long time. 10 | 11 | ## 4.0.0 12 | 13 | * Major version bump due to a change in HTML markup in 9eb3ec4f134e34c93ba8f7927764e9e005de3fe7. You might need to update your styles/CSS. 14 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2013 webfactory GmbH, Bonn (info@webfactory.de) 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to 7 | deal 8 | in the Software without restriction, including without limitation the rights 9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | copies of the Software, and to permit persons to whom the Software is 11 | furnished to do so, subject to the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be included in 14 | all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 21 | FROM, 22 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 | THE SOFTWARE. 24 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # WebfactoryExceptionsBundle 2 | 3 | A Symfony Bundle with some Twig templates and blocks to create helpful, user friendly error pages. 4 | 5 | ⚠️ **Please note:** At webfactory, we do no longer use this bundle in new projects, since its main functionality was merged into Symfony 2.6 and we prefer to have project-specific templates. However, we still use the wording that we provide with this bundle. 6 | 7 | ## Basic Usage 8 | 9 | First, follow the [Symfony Documentation](https://symfony.com/doc/current/controller/error_pages.html) to learn how to create and preview custom error pages. Been there, done that? Fine! 10 | 11 | Let's say your generic error page extends the base layout of MyWebsiteBundle. Then you may want to have your 12 | `error.html.twig` to look something like this: 13 | 14 | {# error.html.twig #} 15 | {% extends '@MyWebsite/Layout/base.html.twig' %} 16 | {% use '@WebfactoryExceptions/Exception/blocks.html.twig' %} 17 | 18 | {% block myMainContentContainer %} 19 | {{ block('webfactory_exceptions_standardExceptionPage') }} 20 | {% endblock %} 21 | 22 | The `webfactory_exceptions_standardExceptionPage` block has headings, the translated exception description and provides 23 | the user with a list of alternatives what they can do next: get back (simulating a browser back), get to the homepage, 24 | get to the contact page or google the domain. It may look like this: 25 | 26 | ![Sample rendering of the webfactory_exceptions_standardExceptionPage block](src/Resources/doc/images/webfactory_exceptions_standardExceptionPage-example.png) 27 | 28 | ## Links to Homepage and Contact Page 29 | 30 | A default block in the bundle provides a link to the homepage with the default target `/`. If your application does not 31 | start at `/`, you need to set the variable `homepageUrl`. 32 | 33 | Also, you may want to set the variable `contactUrl` to get a link to your contact page in the listed alternatives. 34 | 35 | {# error.html.twig #} 36 | {% extends '@MyWebsite/Layout/base.html.twig' %} 37 | {% use '@WebfactoryExceptions/Exception/blocks.html.twig' %} 38 | 39 | {% set homepageUrl = "https://www.webfactory.de" %} 40 | {% set contactUrl = path('name_of_a_route') %} 41 | 42 | {# your blocks and definitions... #} 43 | 44 | ## Filling in Blocks of Base Layouts 45 | 46 | If your base layout already features blocks you need to fill with exception specific content, you can do it this way: 47 | 48 | {# error.html.twig #} 49 | {% extends '@MyWebsite/Layout/base.html.twig' %} 50 | 51 | {% use '@WebfactoryExceptions/Exception/blocks.html.twig' with 52 | webfactory_exceptions_error_title as title, 53 | webfactory_exceptions_error_headline as stage_headline 54 | %} 55 | 56 | This loads the `webfactory_exceptions_error_title` block *directly* into the `title` block of your base layout, as well 57 | as the `webfactory_exceptions_error_headline` block into the `stage_headline` block. 58 | 59 | Happy error-styling! 60 | 61 | ## Credits, Copyright and License 62 | 63 | This bundle was started at webfactory GmbH, Bonn. It was inspired by the blog post [How Symfony2 turns exceptions into error pages and how to customize those](https://www.webfactory.de/blog/symfony2-exception-handling-and-custom-error-pages-explained). 64 | 65 | Previous releases of this bundle contained extra code that would help during development to preview your error pages. This code, however, could be merged into the Symfony core in Symfony 2.6, so we could finally remove it from this bundle. Read the [announcement](https://symfony.com/blog/new-in-symfony-2-6-error-page-previews) when you're interested in historic details. 66 | 67 | - 68 | - 69 | 70 | Copyright 2012-2022 webfactory GmbH, Bonn. Code released under [the MIT license](LICENSE). 71 | -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "webfactory/exceptions-bundle", 3 | 4 | "type": "symfony-bundle", 5 | 6 | "description": "Building blocks for more user-friendly error pages, plus a simple controller to display error pages during development (helpful prior to Symfony 2.6.3)", 7 | 8 | "homepage": "https://www.webfactory.de/blog/symfony2-exception-handling-and-custom-error-pages-explained", 9 | 10 | "license": "MIT", 11 | 12 | "authors": [ 13 | { 14 | "name": "webfactory GmbH", 15 | "email": "info@webfactory.de", 16 | "homepage": "http://www.webfactory.de", 17 | "role": "Developer" 18 | } 19 | ], 20 | 21 | "autoload": { 22 | "psr-4": { "Webfactory\\Bundle\\ExceptionsBundle\\": "src" } 23 | }, 24 | 25 | "require": { 26 | "symfony/http-kernel": "^3.4|^4.4|^5.0|^6.0|^7.0" 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/Resources/doc/images/webfactory_exceptions_standardExceptionPage-example.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/webfactory/exceptions-bundle/83a65ad3c06240b6b54e96f91a27d0e41b35c80d/src/Resources/doc/images/webfactory_exceptions_standardExceptionPage-example.png -------------------------------------------------------------------------------- /src/Resources/translations/webfactory-exceptions-bundle.de.yml: -------------------------------------------------------------------------------- 1 | 2 | sorry: 3 | title: Entschuldigung! 4 | footer: Wir entschuldigen uns für die Unannehmlichkeiten! 5 | 6 | tryAgain: 7 | text: Bitte überprüfen Sie die aufgerufene Adresse: 8 | button: Nochmal versuchen 9 | 10 | error: 11 | 400: 12 | title: Ungültige Anfrage 13 | description: Der Server konnte die Anfrage nicht verarbeiten, weil anscheinend ein clientseitiger Fehler geschehen ist (z.B. eine syntaktisch falsche Anfrage). 14 | 403: 15 | title: Zugriff verweigert 16 | description: Sie besitzen nicht die erforderlichen Berechtigungen, um diese Seite aufzurufen. 17 | 404: 18 | title: Dokument nicht gefunden 19 | description: | 20 | Leider konnte das von Ihnen gewünschte Dokument nicht gefunden werden. 21 | Möglicherweise wurde es inzwischen vom Server entfernt oder ist nicht mehr abrufbar. 22 | 405: 23 | title: Zugriffsmethode nicht unterstützt 24 | description: Die von Ihnen verwendete HTTP-Zugriffsmethode wird für diese URL nicht unterstützt. 25 | 500: 26 | title: Interner Serverfehler 27 | description: | 28 | Beim Generieren der Seite ist ein Fehler aufgetreten. 29 | Alle zum Beheben des Fehlers nötigen Informationen wurden aufgezeichnet und der zuständigen Stelle zugeleitet. 30 | 31 | alternatives: 32 | title: Was nun? 33 | description: Sie können ... 34 | action: 35 | back: zurück zur %link%vorherigen Seite%endlink% gehen, 36 | start: zur %link%Startseite%endlink% wechseln, 37 | search: 38 | description: unsere Website nach einem Suchbegriff durchsuchen (via Google) 39 | button: Suchen 40 | contact: oder %link%Kontakt mit uns%endlink% aufnehmen. 41 | -------------------------------------------------------------------------------- /src/Resources/translations/webfactory-exceptions-bundle.en.yml: -------------------------------------------------------------------------------- 1 | 2 | sorry: 3 | title: Sorry! 4 | footer: We apologize for the inconvenience! 5 | 6 | tryAgain: 7 | text: Please verify the requested address: 8 | button: Try again 9 | 10 | error: 11 | 400: 12 | title: Bad request 13 | description: The server cannot or will not process the request due to something that is perceived to be a client error (for example, malformed request syntax, invalid request message framing, or deceptive request routing). 14 | 403: 15 | title: Access denied 16 | description: You do not have the required permissions to access this page. 17 | 404: 18 | title: Page not found 19 | description: | 20 | There is no content at this address. 21 | It appears you followed a broken or outdated link from a search engine. 22 | 405: 23 | title: Request method not supported 24 | description: The HTTP request method you've used is not supported at this URL. 25 | 500: 26 | title: Internal server error 27 | description: | 28 | A error occured while generating the page. 29 | The information necessary to resolve the problem has been recorded and forwarded to the relevant authority. 30 | 31 | alternatives: 32 | title: Where to go from here? 33 | description: You may want to 34 | action: 35 | back: go back to the %link%previous%endlink% page, 36 | start: start over at our %link%home page%endlink%, 37 | search: 38 | description: search our site for a keyword (via Google) 39 | button: Search 40 | contact: or %link%contact us%endlink%. 41 | -------------------------------------------------------------------------------- /src/Resources/translations/webfactory-exceptions-bundle.fr.yml: -------------------------------------------------------------------------------- 1 | sorry: 2 | title: Excusez nous! 3 | footer: Nous vous présentons nos excuses pour ce désagrément! 4 | 5 | tryAgain: 6 | text: S'il vous plait veuillez vérifier cette adresse 7 | button: Essayez à nouveau 8 | 9 | error: 10 | 403: 11 | title: Accès refusé 12 | description: Vous n'avez pas les permissions requises pour accèder à cette page. 13 | 404: 14 | title: Page non trouvée 15 | description: | 16 | Il n'y a pas de contenu à cette adresse. 17 | Il semble que vous ayez suivi un lien cassé ou n'étant plus à jour depuis un moteur de recherche. 18 | 405: 19 | title: Méthode non supportée 20 | description: La méthode HTTP que vous avez utilisée n'est pas supportée à cette adresse. 21 | 500: 22 | title: Erreur interne du serveur 23 | description: | 24 | Une erreur est apparue pendant la génération de cette page. 25 | Les informations nécessaires pour résoudre ce problème ont été enregistrées et envoyées aux autorités compétentes. 26 | alternatives: 27 | title: Où allez à partir d'ici? 28 | description: Vous aimeriez peut être 29 | action: 30 | back: revenir en arrière sur la page %link%précédente%endlink%, 31 | start: vous diriger vers la %link%page d'accueil%endlink%, 32 | search: 33 | description: chercher à partir d'un mot clef (via Google) 34 | button: Rechercher 35 | contact: ou %link%nous contacter%endlink%. 36 | -------------------------------------------------------------------------------- /src/Resources/translations/webfactory-exceptions-bundle.hr.yml: -------------------------------------------------------------------------------- 1 | 2 | sorry: 3 | title: Oprostite! 4 | footer: Ispričavamo se zbog neugodnosti! 5 | 6 | tryAgain: 7 | text: Molimo provjerite traženu adresu: 8 | button: Pokušajte ponovo 9 | 10 | error: 11 | 403: 12 | title: Pristup odbijen 13 | description: Nemate potrebne ovlasti za pristup ovoj stranici. 14 | 404: 15 | title: Stranica nije pronađena 16 | description: | 17 | Nema sadržaja na ovoj adresi. 18 | Čini se da slijedili neispravan ili zastarjeli link iz tražilice. 19 | 405: 20 | title: Metoda zahtjeva nije podržana 21 | description: HTTP metoda zahtjeva koji ste se koristili nije podržana na ovom URL-u. 22 | 500: 23 | title: Interna pogreška poslužitelja 24 | description: | 25 | Došlo je do pogreške tijekom prikazivanja stranice. 26 | Informacije potrebne za rješavanje problema su snimljene i proslijeđene nadležnoj osobi. 27 | 28 | alternatives: 29 | title: Kuda dalje? 30 | description: Možda želite pogledati 31 | action: 32 | back: natrag na %link%prethodnu%endlink% stranicu, 33 | start: krenite ispočetka na %link%početnoj stranici%endlink%, 34 | search: 35 | description: Pretražite naše stranice ( preko Googlea ) 36 | button: Pretraži 37 | contact: ili %link%nas kontaktirajte%endlink%. 38 | -------------------------------------------------------------------------------- /src/Resources/translations/webfactory-exceptions-bundle.it.yml: -------------------------------------------------------------------------------- 1 | 2 | sorry: 3 | title: Ci scusi! 4 | footer: Ci scusiamo per il disagio! 5 | 6 | tryAgain: 7 | text: Si prega di verificare l'indirizzo richiesto: 8 | button: Riprova 9 | 10 | error: 11 | 403: 12 | title: Accesso negato 13 | description: Non disponi delle autorizzazioni necessarie per accedere a questa pagina. 14 | 404: 15 | title: Pagina non trovata 16 | description: | 17 | Non ci sono contenuti su questo indirizzo 18 | Sembra hai raggiunto un link non funzionante o non aggiornato da un motore di ricerca. 19 | 405: 20 | title: Richiesta non supportata 21 | description: La richiesta HTTP che hai usato non è supportata da questa URL. 22 | 500: 23 | title: Errore interno del server 24 | description: | 25 | E' avvenuto un errore durante la generazione della pagina. 26 | Le informazioni necessarie per risolvere il problema sono state registrate e trasmesse all'autorità competente. 27 | 28 | alternatives: 29 | title: Cosa vuoi fare adesso? 30 | description: Potresti voler: 31 | action: 32 | back: tornare alla %link%precedente%endlink% pagina, 33 | start: andare alla %link%home page%endlink%, 34 | search: 35 | description: cercare tramite keyword sul nostro sito (via Google) 36 | button: Cerca 37 | contact: o %link%contattarci%endlink%. -------------------------------------------------------------------------------- /src/Resources/views/Exception/blocks.html.twig: -------------------------------------------------------------------------------- 1 | {%- block webfactory_exceptions_error_code -%} 2 | {{ exception.getStatusCode }} 3 | {%- endblock -%} 4 | 5 | {%- block webfactory_exceptions_error_title -%} 6 | {{ ("error." ~ exception.getStatusCode ~ ".title")|trans({}, 'webfactory-exceptions-bundle') }} 7 | {%- endblock -%} 8 | 9 | {%- block webfactory_exceptions_error_description -%} 10 | {{ ("error." ~ exception.getStatusCode ~ ".description")|trans({}, 'webfactory-exceptions-bundle')|nl2br }} 11 | {%- endblock -%} 12 | 13 | {%- block webfactory_exceptions_error_headline -%} 14 | {{ block('webfactory_exceptions_error_title') }} ({{ block('webfactory_exceptions_error_code') }}) 15 | {%- endblock -%} 16 | 17 | {%- block webfactory_exceptions_sorry_title -%} 18 | {{ ("sorry.title")|trans({}, 'webfactory-exceptions-bundle') }} 19 | {%- endblock -%} 20 | 21 | {%- block webfactory_exceptions_sorry_footer -%} 22 | {{ ("sorry.footer")|trans({}, 'webfactory-exceptions-bundle')|nl2br }} 23 | {%- endblock -%} 24 | 25 | {% block webfactory_exceptions_standardExceptionPage %} 26 |

{{ block('webfactory_exceptions_error_headline') }}

27 |

{{ block('webfactory_exceptions_sorry_title') }}

28 |

{{ block('webfactory_exceptions_error_description') }}

29 | 30 | {{ block('webfactory_exceptions_standardAlternatives') }} 31 | 32 | {{ block('webfactory_exceptions_sorry_footer') }} 33 | {% endblock %} 34 | 35 | {% block webfactory_exceptions_standardAlternatives %} 36 |

{{ "alternatives.title"|trans({},'webfactory-exceptions-bundle') }}

37 |

{{ "alternatives.description"|trans({},'webfactory-exceptions-bundle') }}

38 | 46 | {% endblock %} 47 | 48 | {% block webfactory_exceptions_actionBack %} 49 | {% set link %}{% endset %} 50 | {% set endlink %}{% endset %} 51 | {{ "alternatives.action.back"|trans({'%link%':link, '%endlink%': endlink},'webfactory-exceptions-bundle')|raw }} 52 | {% endblock %} 53 | 54 | {% block webfactory_exceptions_actionGetToHomepage %} 55 | {% set link %}{% endset %} 56 | {% set endlink %}{% endset %} 57 | {{ "alternatives.action.start"|trans({'%link%':link, '%endlink%': endlink},'webfactory-exceptions-bundle')|raw }} 58 | {% endblock %} 59 | 60 | {# @deprecated: use webfactory_exceptions_actionGetToHomepage instead #} 61 | {% block webfactory_exceptions_actionZurStartseiteWechseln %} 62 | {% if startseiteUrl is defined %} 63 | {% set homepageUrl = startseiteUrl %} 64 | {% endif %} 65 | {{ block('webfactory_exceptions_actionGetToHomepage') }} 66 | {% endblock %} 67 | 68 | {% block webfactory_exceptions_actionGoogleSearch %} 69 |
70 |
71 | 72 | 73 |
74 |
75 | {% endblock %} 76 | 77 | {% block webfactory_exceptions_actionGetInContact %} 78 | {% set link %}{% endset %} 79 | {% set endlink %}{% endset %} 80 | {{ "alternatives.action.contact"|trans({'%link%':link, '%endlink%': endlink},'webfactory-exceptions-bundle')|raw }} 81 | {% endblock %} 82 | 83 | {# @deprecated: use webfactory_exceptions_actionGetInContact instead #} 84 | {% block webfactory_exceptions_actionKontaktAufnehmen %} 85 | {% if kontaktUrl is defined %} 86 | {% set contactUrl = kontaktUrl %} 87 | {% endif %} 88 | {{ block('webfactory_exceptions_actionGetInContact') }} 89 | {% endblock %} 90 | 91 | {% block webfactory_exceptions_tryAgain %} 92 |
93 |
94 | 95 | 96 | 97 |
98 |
99 | {% endblock %} 100 | -------------------------------------------------------------------------------- /src/WebfactoryExceptionsBundle.php: -------------------------------------------------------------------------------- 1 | 4 | * 5 | * For the full copyright and license information, please view the LICENSE 6 | * file that was distributed with this source code. 7 | */ 8 | 9 | namespace Webfactory\Bundle\ExceptionsBundle; 10 | 11 | use Symfony\Component\HttpKernel\Bundle\Bundle; 12 | 13 | class WebfactoryExceptionsBundle extends Bundle 14 | { 15 | } 16 | --------------------------------------------------------------------------------