Skip to content

Commit d19e2a8

Browse files
committed
Merge branch '6.0' into 6.1
* 6.0: [HttpKernel] 15874 framework exceptions
2 parents 376079f + a540576 commit d19e2a8

File tree

1 file changed

+74
-0
lines changed

1 file changed

+74
-0
lines changed

reference/configuration/framework.rst

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3220,6 +3220,80 @@ Defines the kind of workflow that is going to be created, which can be either
32203220
a normal workflow or a state machine. Read :doc:`this article </workflow/workflow-and-state-machine>`
32213221
to know their differences.
32223222

3223+
exceptions
3224+
""""""""""
3225+
3226+
**type**: ``array``
3227+
3228+
Defines the :ref:`log level </logging>` and HTTP status code applied to the
3229+
exceptions that match the given exception class:
3230+
3231+
.. configuration-block::
3232+
3233+
.. code-block:: yaml
3234+
3235+
# config/packages/exceptions.yaml
3236+
framework:
3237+
exceptions:
3238+
Symfony\Component\HttpKernel\Exception\BadRequestHttpException:
3239+
log_level: 'debug'
3240+
status_code: 422
3241+
3242+
.. code-block:: xml
3243+
3244+
<!-- config/packages/exceptions.xml -->
3245+
<?xml version="1.0" encoding="UTF-8" ?>
3246+
<container xmlns="http://symfony.com/schema/dic/services"
3247+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3248+
xmlns:framework="http://symfony.com/schema/dic/symfony"
3249+
xsi:schemaLocation="http://symfony.com/schema/dic/services
3250+
https://symfony.com/schema/dic/services/services-1.0.xsd
3251+
http://symfony.com/schema/dic/symfony https://symfony.com/schema/dic/symfony/symfony-1.0.xsd">
3252+
3253+
<framework:config>
3254+
<framework:exceptions>
3255+
<exception id="Symfony\Component\HttpKernel\Exception\BadRequestHttpException">
3256+
<framework:log_level>debug</framework:log_level>
3257+
<framework:status_code>422</framework:status_code>
3258+
</exception>
3259+
</framework:exceptions>
3260+
<!-- ... -->
3261+
</framework:config>
3262+
</container>
3263+
3264+
.. code-block:: php
3265+
3266+
// config/packages/exceptions.php
3267+
use Symfony\Component\HttpKernel\Exception\BadRequestHttpException;
3268+
use Symfony\Config\FrameworkConfig;
3269+
3270+
return static function (FrameworkConfig $framework) {
3271+
$framework
3272+
->exceptions(BadRequestHttpException::class)
3273+
->log_level('debug');
3274+
3275+
$framework
3276+
->exceptions(BadRequestHttpException::class)
3277+
->status_code(422);
3278+
;
3279+
};
3280+
3281+
The order in which you configure exceptions is important because Symfony will
3282+
use the configuration of the first exception that matches ``instanceof``:
3283+
3284+
.. code-block:: yaml
3285+
3286+
# config/packages/exceptions.yaml
3287+
framework:
3288+
exceptions:
3289+
Exception:
3290+
log_level: 'debug'
3291+
status_code: 404
3292+
# The following configuration will never be used because \RuntimeException extends \Exception
3293+
RuntimeException:
3294+
log_level: 'debug'
3295+
status_code: 422
3296+
32233297
.. _`HTTP Host header attacks`: https://www.skeletonscribe.net/2013/05/practical-http-host-header-attacks.html
32243298
.. _`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
32253299
.. _`PhpStormProtocol`: https://github.com/aik099/PhpStormProtocol

0 commit comments

Comments
 (0)