Skip to content

Commit

Permalink
minor FriendsOfSymfony#1411 Update the exception listener doc (Ener-G…
Browse files Browse the repository at this point in the history
…etick)

This PR was merged into the 2.0 branch.

Discussion
----------

Update the exception listener doc

See FriendsOfSymfony#1410

cc @xabbuh

Commits
-------

bace54a Update the exception listener doc
  • Loading branch information
xabbuh committed Apr 3, 2016
2 parents 6941cb3 + bace54a commit 999f487
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 29 deletions.
2 changes: 1 addition & 1 deletion DependencyInjection/Compiler/TwigExceptionPass.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
use Symfony\Component\DependencyInjection\ContainerBuilder;

/**
* Remove the 'twig.exception_listener' service if 'fos_rest.exception_listener' is activated.
* Remove the 'fos_rest.exception.twig_controller' service if twig is enabled.
*
* @internal
*/
Expand Down
37 changes: 9 additions & 28 deletions Resources/doc/4-exception-controller-support.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,8 @@ bundle provides an extra controller for that job. Using this custom
ExceptionController it is possible to leverage the View layer when building
responses for uncaught Exceptions.

The ExceptionController can be enabled either via the FOSRestBundle
configuration and optionally an explicit controller action can be configured as
well:
The ExceptionController can be enabled via the FOSRestBundle
configuration:

.. code-block:: yaml
Expand All @@ -19,13 +18,9 @@ well:
enabled: true
exception_controller: 'Acme\DemoBundle\Controller\ExceptionController::showAction'
Alternatively the TwigBundle configuration can be used to enable the ExceptionController:

.. code-block:: yaml
.. note::

# app/config/config.yml
twig:
exception_controller: 'fos_rest.exception.twig_controller:showAction'
The FOSRestBundle ExceptionController is executed before the one of the TwigBundle.

.. note::

Expand All @@ -36,9 +31,6 @@ Alternatively the TwigBundle configuration can be used to enable the ExceptionCo
``fos_rest.exception.twig_controller`` which additionally also supports
rendering via Twig.

When enabling the RestBundle view-layer-aware ExceptionController it automatically
disables the TwigBundle exception listener and subsequent configuration.

To map Exception classes to HTTP response status codes an *exception map* may
be configured, where the keys match a fully qualified class name and the values
are either an integer HTTP response status code or a string matching a class
Expand Down Expand Up @@ -76,28 +68,17 @@ mapping, you can do this in your controller:
}
In order to make the serialization format of exceptions customizable it is possible to
configure a ``exception_handler``. Users of JMS serializer can further customize the output
by setting a custom ``exception_wrapper_handler``.

.. code-block:: yaml
# app/config/config.yml
fos_rest:
service:
exception_handler: fos_rest.view.exception_wrapper_handler
view:
# only relevant when using the JMS serializer for serialization
exception_wrapper_handler: null
use serializer normalizers.

See `this example configuration`_ for more details.
See `how to create handlers`_ for the JMS serializer and `how to create normalizers`_ for the Symfony serializer.

That was it!

.. note::

If you are receiving a 500 error where you would expect a different response, the issue
is likely caused by an exception inside the ExceptionController. For example a template
is not found or the serializer failed.
is not found or the serializer failed. You should take a look at the logs of your app to see if an uncaught exception has been logged.

.. _`this example configuration`: https://github.com/liip-forks/symfony-standard/blob/techtalk/app/config/config.yml
.. _`how to create handlers`: http://jmsyst.com/libs/serializer/master/handlers
.. _`how to create normalizers`: http://thomas.jarrand.fr/blog/serialization/

0 comments on commit 999f487

Please sign in to comment.