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