Commit 902c3748 authored by Fabien Potencier's avatar Fabien Potencier

added a note in the docs

parent 791ad2a4
......@@ -522,7 +522,7 @@ takes an ``Exception`` argument and returns a response::
use Symfony\Component\HttpFoundation\Response;
$app->error(function (\Exception $e, $code) {
return new Response('We are sorry, but something went terribly wrong.', $code);
return new Response('We are sorry, but something went terribly wrong.');
});
You can also check for specific errors by using the ``$code`` argument, and
......@@ -539,9 +539,18 @@ handle them differently::
$message = 'We are sorry, but something went terribly wrong.';
}
return new Response($message, $code);
return new Response($message);
});
.. note::
As Silex ensures that the Response status code is set to the most
appropriate one depending on the exception, setting the status on the
response won't work. If you want to overwrite the status code (which you
should not without a good reason), set the ``X-Status-Code`` header::
return new Response('Error', 404 /* ignored */, array('X-Status-Code' => 200));
You can restrict an error handler to only handle some Exception classes by
setting a more specific type hint for the Closure argument::
......
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