@@ -3316,6 +3316,80 @@ Defines the kind of workflow that is going to be created, which can be either
33163316a normal workflow or a state machine. Read :doc: `this article </workflow/workflow-and-state-machine >`
33173317to know their differences.
33183318
3319+ exceptions
3320+ """"""""""
3321+
3322+ **type **: ``array ``
3323+
3324+ Defines what ``log_level `` and ``status_code `` should be returned by exception class:
3325+
3326+ .. configuration-block ::
3327+
3328+ .. code-block :: yaml
3329+
3330+ # config/packages/exceptions.yaml
3331+ framework :
3332+ exceptions :
3333+ Symfony\Component\HttpKernel\Exception\BadRequestHttpException :
3334+ log_level : debug
3335+ status_code : 422
3336+
3337+ .. code-block :: xml
3338+
3339+ <!-- config/packages/exceptions.xml -->
3340+ <?xml version =" 1.0" encoding =" UTF-8" ?>
3341+ <container xmlns =" http://symfony.com/schema/dic/services"
3342+ xmlns : xsi =" http://www.w3.org/2001/XMLSchema-instance"
3343+ xmlns : framework =" http://symfony.com/schema/dic/symfony"
3344+ xsi : schemaLocation =" http://symfony.com/schema/dic/services
3345+ https://symfony.com/schema/dic/services/services-1.0.xsd
3346+ http://symfony.com/schema/dic/symfony https://symfony.com/schema/dic/symfony/symfony-1.0.xsd" >
3347+
3348+ <framework : config >
3349+ <framework : exceptions >
3350+ <exception id =" Symfony\Component\HttpKernel\Exception\BadRequestHttpException" >
3351+ <framework : log_level >debug</framework : log_level >
3352+ <framework : status_code >422</framework : status_code >
3353+ </exception >
3354+ </framework : exceptions >
3355+ <!-- ... -->
3356+ </framework : config >
3357+ </container >
3358+
3359+ .. code-block :: php
3360+
3361+ // config/packages/exceptions.php
3362+ use Symfony\Config\FrameworkConfig;
3363+
3364+ return static function (FrameworkConfig $framework) {
3365+ $framework
3366+ ->exceptions('Symfony\Component\HttpKernel\Exception\BadRequestHttpException')
3367+ ->log_level('debug');
3368+
3369+ $framework
3370+ ->exceptions('Symfony\Component\HttpKernel\Exception\BadRequestHttpException')
3371+ ->status_code(422);
3372+ ;
3373+ };
3374+
3375+ .. note ::
3376+
3377+ When defining exceptions the order is important as it will use the first exception that matches ``instanceof ``
3378+
3379+ Example with ``\RuntimeException `` and ``\Exception ``:
3380+
3381+ .. code-block :: yaml
3382+
3383+ # config/packages/exceptions.yaml
3384+ framework :
3385+ exceptions :
3386+ Exception :
3387+ log_level : debug
3388+ status_code : 404
3389+ RuntimeException : # This will never be used as \RuntimeException extends \Exception
3390+ log_level : debug
3391+ status_code : 422
3392+
33193393 .. _`HTTP Host header attacks` : https://www.skeletonscribe.net/2013/05/practical-http-host-header-attacks.html
33203394.. _`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
33213395.. _`Doctrine Cache` : https://www.doctrine-project.org/projects/doctrine-cache/en/current/index.html
0 commit comments