Commit 0aa47527 authored by Fabien Potencier's avatar Fabien Potencier

minor #993 Update "Error Handlers" part in usage.rst (Poisbeau Mathieu)

This PR was merged into the 2.0.x-dev branch.

Discussion
----------

Update "Error Handlers" part in usage.rst

Update "Error Handlers" part in usage.rst because of https://github.com/silexphp/Silex/commit/e96f9be8fda96193313bb655d63b061d6d4d7c4d#diff-9460b640f6466d5890f37f7caf262024R52

Commits
-------

46f125c4 Update "Error Handlers" part in usage.rst
parents 3e2f70ed 46f125c4
......@@ -489,8 +489,9 @@ To register an error handler, pass a closure to the ``error`` method which
takes an ``Exception`` argument and returns a response::
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\Request;
$app->error(function (\Exception $e, $request, $code) {
$app->error(function (\Exception $e, Request $request, $code) {
return new Response('We are sorry, but something went terribly wrong.');
});
......@@ -498,8 +499,9 @@ You can also check for specific errors by using the ``$code`` argument, and
handle them differently::
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\Request;
$app->error(function (\Exception $e, $request, $code) {
$app->error(function (\Exception $e, Request $request, $code) {
switch ($code) {
case 404:
$message = 'The requested page could not be found.';
......@@ -523,7 +525,9 @@ handle them differently::
You can restrict an error handler to only handle some Exception classes by
setting a more specific type hint for the Closure argument::
$app->error(function (\LogicException $e, $request, $code) {
use Symfony\Component\HttpFoundation\Request;
$app->error(function (\LogicException $e, Request $request, $code) {
// this handler will only handle \LogicException exceptions
// and exceptions that extends \LogicException
});
......@@ -546,8 +550,9 @@ once a response is returned, the following handlers are ignored.
is turned on like this::
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\Request;
$app->error(function (\Exception $e, $request, $code) use ($app) {
$app->error(function (\Exception $e, Request $request, $code) use ($app) {
if ($app['debug']) {
return;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment