10000 added a note in the docs · silexphp/Silex@902c374 · GitHub
[go: up one dir, main page]

Skip to content
This repository was archived by the owner on Jul 4, 2018. It is now read-only.

Commit 902c374

Browse files
committed
added a note in the docs
1 parent 791ad2a commit 902c374

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

doc/usage.rst

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -522,7 +522,7 @@ takes an ``Exception`` argument and returns a response::
522522
use Symfony\Component\HttpFoundation\Response;
523523

524524
$app->error(function (\Exception $e, $code) {
525-
return new Response('We are sorry, but something went terribly wrong.', $code);
525+
return new Response('We are sorry, but something went terribly wrong.');
526526
});
527527

528528
You can also check for specific errors by using the ``$code`` argument, and
@@ -539,9 +539,18 @@ handle them differently::
539539
$message = 'We are sorry, but something went terribly wrong.';
540540
}
541541

542-
return new Response($message, $code);
542+
return new Response($message);
543543
});
544544

545+
.. note::
546+
547+
As Silex ensures that the Response status code is set to the most
548+
appropriate one depending on the exception, setting the status on the
549+
response won't work. If you want to overwrite the status code (which you
550+
should not without a good reason), set the ``X-Status-Code`` header::
551+
552+
return new Response('Error', 404 /* ignored */, array('X-Status-Code' => 200));
553+
545554
You can restrict an error handler to only handle some Exception classes by
546555
setting a more specific type hint for the Closure argument::
547556

0 commit comments

Comments
 (0)
0