DefaultExceptionSubscriber::setEventResponse

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

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);
}
doc_Drupal
2016-10-29 09:01:41
Comments
Leave a Comment

Please login to continue.