This repository was archived by the owner on Jul 4, 2018. It is now read-only.
File tree Expand file tree Collapse file tree 1 file changed +11
-2
lines changed Expand file tree Collapse file tree 1 file changed +11
-2
lines changed Original file line number Diff line number Diff line change @@ -522,7 +522,7 @@ takes an ``Exception`` argument and returns a response::
522
522
use Symfony\Component\HttpFoundation\Response;
523
523
524
524
$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.');
526
526
});
527
527
528
528
You can also check for specific errors by using the ``$code `` argument, and
@@ -539,9 +539,18 @@ handle them differently::
539
539
$message = 'We are sorry, but something went terribly wrong.';
540
540
}
541
541
542
- return new Response($message, $code );
542
+ return new Response($message);
543
543
});
544
544
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
+
545
554
You can restrict an error handler to only handle some Exception classes by
546
555
setting a more specific type hint for the Closure argument::
547
556
You can’t perform that action at this time.
0 commit comments