@@ -3358,6 +3358,80 @@ Defines the kind of workflow that is going to be created, which can be either
33583358a normal workflow or a state machine. Read :doc: `this article </workflow/workflow-and-state-machine >`
33593359to know their differences.
33603360
3361+ exceptions
3362+ """"""""""
3363+
3364+ **type **: ``array ``
3365+
3366+ Defines what ``log_level `` and ``status_code `` should be returned by exception class:
3367+
3368+ .. configuration-block ::
3369+
3370+ .. code-block :: yaml
3371+
3372+ # config/packages/exceptions.yaml
3373+ framework :
3374+ exceptions :
3375+ Symfony\Component\HttpKernel\Exception\BadRequestHttpException :
3376+ log_level : debug
3377+ status_code : 422
3378+
3379+ .. code-block :: xml
3380+
3381+ <!-- config/packages/exceptions.xml -->
3382+ <?xml version =" 1.0" encoding =" UTF-8" ?>
3383+ <container xmlns =" http://symfony.com/schema/dic/services"
3384+ xmlns : xsi =" http://www.w3.org/2001/XMLSchema-instance"
3385+ xmlns : framework =" http://symfony.com/schema/dic/symfony"
3386+ xsi : schemaLocation =" http://symfony.com/schema/dic/services
3387+ https://symfony.com/schema/dic/services/services-1.0.xsd
3388+ http://symfony.com/schema/dic/symfony https://symfony.com/schema/dic/symfony/symfony-1.0.xsd" >
3389+
3390+ <framework : config >
3391+ <framework : exceptions >
3392+ <exception id =" Symfony\Component\HttpKernel\Exception\BadRequestHttpException" >
3393+ <framework : log_level >debug</framework : log_level >
3394+ <framework : status_code >422</framework : status_code >
3395+ </exception >
3396+ </framework : exceptions >
3397+ <!-- ... -->
3398+ </framework : config >
3399+ </container >
3400+
3401+ .. code-block :: php
3402+
3403+ // config/packages/exceptions.php
3404+ use Symfony\Config\FrameworkConfig;
3405+
3406+ return static function (FrameworkConfig $framework) {
3407+ $framework
3408+ ->exceptions('Symfony\Component\HttpKernel\Exception\BadRequestHttpException')
3409+ ->log_level('debug');
3410+
3411+ $framework
3412+ ->exceptions('Symfony\Component\HttpKernel\Exception\BadRequestHttpException')
3413+ ->status_code(422);
3414+ ;
3415+ };
3416+
3417+ .. note ::
3418+
3419+ When defining exceptions the order is important as it will use the first exception that matches ``instanceof ``
3420+
3421+ Example with ``\RuntimeException `` and ``\Exception ``:
3422+
3423+ .. code-block :: yaml
3424+
3425+ # config/packages/exceptions.yaml
3426+ framework :
3427+ exceptions :
3428+ Exception :
3429+ log_level : debug
3430+ status_code : 404
3431+ RuntimeException : # This will never be used as \RuntimeException extends \Exception
3432+ log_level : debug
3433+ status_code : 422
3434+
33613435 .. _`HTTP Host header attacks` : https://www.skeletonscribe.net/2013/05/practical-http-host-header-attacks.html
33623436.. _`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
33633437.. _`Doctrine Cache` : https://www.doctrine-project.org/projects/doctrine-cache/en/current/index.html
0 commit comments