File tree Expand file tree Collapse file tree 1 file changed +10
-1
lines changed
cookbook/service_container Expand file tree Collapse file tree 1 file changed +10
-1
lines changed Original file line number Diff line number Diff line change @@ -19,6 +19,7 @@ event is just one of the core kernel events::
19
19
20
20
use Symfony\Component\HttpKernel\Event\GetResponseForExceptionEvent;
21
21
use Symfony\Component\HttpFoundation\Response;
22
+ use Symfony\Component\HttpKernel\Exception\HttpExceptionInterface;
22
23
23
24
class AcmeExceptionListener
24
25
{
@@ -31,7 +32,15 @@ event is just one of the core kernel events::
31
32
// Customize our response object to display our exception details
32
33
$response = new Response();
33
34
$response->setContent($message);
34
- $response->setStatusCode(500);
35
+
36
+ // HttpExceptionInterface is a special type of exception that
37
+ // holds status code and header details
38
+ if ($exception instanceof HttpExceptionInterface) {
39
+ $response->setStatusCode($exception->getStatusCode());
40
+ $response->headers->replace($exception->getHeaders());
41
+ } else {
42
+ $response->setStatusCode(500);
43
+ }
35
44
36
45
// Send our modified response object to the event
37
46
$event->setResponse($response);
You can’t perform that action at this time.
0 commit comments