Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

[HttpKernel] 15874 framework exceptions #15916

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 7, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
74 changes: 74 additions & 0 deletions 74 reference/configuration/framework.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3316,6 +3316,80 @@ Defines the kind of workflow that is going to be created, which can be either
a normal workflow or a state machine. Read :doc:`this article </workflow/workflow-and-state-machine>`
to know their differences.

exceptions
""""""""""

**type**: ``array``

Defines what ``log_level`` and ``status_code`` should be returned by exception class:

.. configuration-block::

.. code-block:: yaml

# config/packages/exceptions.yaml
framework:
exceptions:
Symfony\Component\HttpKernel\Exception\BadRequestHttpException:
log_level: debug
status_code: 422

.. code-block:: xml

<!-- config/packages/exceptions.xml -->
<?xml version="1.0" encoding="UTF-8" ?>
<container xmlns="http://symfony.com/schema/dic/services"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:framework="http://symfony.com/schema/dic/symfony"
xsi:schemaLocation="http://symfony.com/schema/dic/services
https://symfony.com/schema/dic/services/services-1.0.xsd
http://symfony.com/schema/dic/symfony https://symfony.com/schema/dic/symfony/symfony-1.0.xsd">

<framework:config>
<framework:exceptions>
<exception id="Symfony\Component\HttpKernel\Exception\BadRequestHttpException">
<framework:log_level>debug</framework:log_level>
<framework:status_code>422</framework:status_code>
</exception>
</framework:exceptions>
<!-- ... -->
</framework:config>
</container>

.. code-block:: php

// config/packages/exceptions.php
use Symfony\Config\FrameworkConfig;

return static function (FrameworkConfig $framework) {
$framework
->exceptions('Symfony\Component\HttpKernel\Exception\BadRequestHttpException')
->log_level('debug');

$framework
->exceptions('Symfony\Component\HttpKernel\Exception\BadRequestHttpException')
->status_code(422);
;
};

.. note::

When defining exceptions the order is important as it will use the first exception that matches ``instanceof``

Example with ``\RuntimeException`` and ``\Exception``:

.. code-block:: yaml

# config/packages/exceptions.yaml
framework:
exceptions:
Exception:
log_level: debug
status_code: 404
RuntimeException: # This will never be used as \RuntimeException extends \Exception
log_level: debug
status_code: 422

.. _`HTTP Host header attacks`: https://www.skeletonscribe.net/2013/05/practical-http-host-header-attacks.html
.. _`Security Advisory Blog post`: https://symfony.com/blog/security-releases-symfony-2-0-24-2-1-12-2-2-5-and-2-3-3-released#cve-2013-4752-request-gethost-poisoning
.. _`Doctrine Cache`: https://www.doctrine-project.org/projects/doctrine-cache/en/current/index.html
Expand Down
Morty Proxy This is a proxified and sanitized view of the page, visit original site.