Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Symfony ErrorHandler

Symfony ErrorHandler

In Symfony 4.4 the Debug component was replaced with the new ErrorHandler component. Let's have a quick look what changed and how you can use the component both in Symfony or standalone.

Denis Brumann

February 25, 2020
Tweet

More Decks by Denis Brumann

Other Decks in Programming

Transcript

  1. Symfony
    Error Handler
    Denis Brumann
    [email protected]
    ⁉ @dbrumann

    View full-size slide

  2. Throwable
    Error Exception

    View full-size slide

  3. Symfony\Component\ErrorHandler\
    ErrorHandler::register()

    View full-size slide

  4. Symfony\Component\ErrorHandler\
    DebugClassLoader::enable()

    View full-size slide

  5. Rendering error pages

    View full-size slide

  6. Routing Configuration
    _errors:
    resource: '@FrameworkBundle/Resources/config/routing/errors.xml'
    prefix: /_error

    View full-size slide

  7. HTML
    JSON
    XML
    YAML

    View full-size slide

  8. ErrorRenderer

    View full-size slide

  9. Customizing Error Pages

    View full-size slide

  10. TwigBundle Resources

    View full-size slide

  11. Non-HTML Resources
    implements
    Symfony\Component\Serializer\Normalizer\
    NormalizerInterface

    View full-size slide

  12. public function supportsNormalization($data, string $format = null)
    {
    return $data instanceof FlattenException;
    }

    View full-size slide

  13. Symfony\Component\HttpKernel\
    EventListener\ErrorListener
    Symfony\Component\Console\
    EventListener\ErrorListener

    View full-size slide

  14. Symfony\Component\HttpKernel\
    Controller\ErrorController

    View full-size slide

  15. Custom Error Controller

    View full-size slide

  16. HTML
    JSON
    XML
    Symfony\Component\Serializer\Normalizer\
    NormalizerInterface

    View full-size slide

  17. HTML
    JSON
    XML
    composer require twig
    composer require serializer

    View full-size slide

  18. Docs
    https://symfony.com/doc/current/components/error_handler.html
    https://symfony.com/doc/current/controller/error_pages.html

    View full-size slide