protected DefaultExceptionSubscriber::setEventResponse(GetResponseForExceptionEvent $event, $status)
Sets the Response for the exception event.
Parameters
\Symfony\Component\HttpKernel\Event\GetResponseForExceptionEvent $event: The current exception event.
int $status: The HTTP status code to set for the response.
File
- core/modules/serialization/src/EventSubscriber/DefaultExceptionSubscriber.php, line 136
Class
- DefaultExceptionSubscriber
- Handles default error responses in serialization formats.
Namespace
Drupal\serialization\EventSubscriber
Code
1 2 3 4 5 6 7 | protected function setEventResponse(GetResponseForExceptionEvent $event , $status ) { $format = $event ->getRequest()->getRequestFormat(); $content = [ 'message' => $event ->getException()->getMessage()]; $encoded_content = $this ->serializer->serialize( $content , $format ); $response = new Response( $encoded_content , $status ); $event ->setResponse( $response ); } |
Please login to continue.