Skip to content

Replace ExceptionListener uses with ErrorListener #13391

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 24, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions create_framework/dependency_injection.rst
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ to it::
$argumentResolver = new HttpKernel\Controller\ArgumentResolver();

$dispatcher = new EventDispatcher();
$dispatcher->addSubscriber(new HttpKernel\EventListener\ExceptionListener(
$dispatcher->addSubscriber(new HttpKernel\EventListener\ErrorListener(
'Calendar\Controller\ErrorController::exception'
));
$dispatcher->addSubscriber(new HttpKernel\EventListener\RouterListener($matcher, $requestStack));
Expand Down Expand Up @@ -124,7 +124,7 @@ Create a new file to host the dependency injection container configuration::
$containerBuilder->register('listener.response', HttpKernel\EventListener\ResponseListener::class)
->setArguments(['UTF-8'])
;
$containerBuilder->register('listener.exception', HttpKernel\EventListener\ExceptionListener::class)
$containerBuilder->register('listener.exception', HttpKernel\EventListener\ErrorListener::class)
->setArguments(['Calendar\Controller\ErrorController::exception'])
;
$containerBuilder->register('dispatcher', EventDispatcher\EventDispatcher::class)
Expand Down
8 changes: 4 additions & 4 deletions create_framework/http_kernel_httpkernel_class.rst
Original file line number Diff line number Diff line change
Expand Up @@ -66,22 +66,22 @@ framework: it matches the incoming request and populates the request
attributes with route parameters.

Our code is now much more concise and surprisingly more robust and more
powerful than ever. For instance, use the built-in ``ExceptionListener`` to
powerful than ever. For instance, use the built-in ``ErrorListener`` to
make your error management configurable::

$errorHandler = function (Symfony\Component\ErrorHandler\Exception\FlattenException $exception) {
$msg = 'Something went wrong! ('.$exception->getMessage().')';

return new Response($msg, $exception->getStatusCode());
};
$dispatcher->addSubscriber(new HttpKernel\EventListener\ExceptionListener($errorHandler));
$dispatcher->addSubscriber(new HttpKernel\EventListener\ErrorListener($errorHandler));

``ExceptionListener`` gives you a ``FlattenException`` instance instead of the
``ErrorListener`` gives you a ``FlattenException`` instance instead of the
thrown ``Exception`` or ``Error`` instance to ease exception manipulation and
display. It can take any valid controller as an exception handler, so you can
create an ErrorController class instead of using a Closure::

$listener = new HttpKernel\EventListener\ExceptionListener(
$listener = new HttpKernel\EventListener\ErrorListener(
'Calendar\Controller\ErrorController::exception'
);
$dispatcher->addSubscriber($listener);
Expand Down