protected function DefaultExceptionSubscriber::setEventResponse in JSON:API 8.2
Same name and namespace in other branches
- 8 src/EventSubscriber/DefaultExceptionSubscriber.php \Drupal\jsonapi\EventSubscriber\DefaultExceptionSubscriber::setEventResponse()
1 call to DefaultExceptionSubscriber::setEventResponse()
- DefaultExceptionSubscriber::onException in src/
EventSubscriber/ DefaultExceptionSubscriber.php - Handles errors for this subscriber.
File
- src/
EventSubscriber/ DefaultExceptionSubscriber.php, line 58
Class
- DefaultExceptionSubscriber
- Serializes exceptions in compliance with the JSON:API specification.
Namespace
Drupal\jsonapi\EventSubscriberCode
protected function setEventResponse(GetResponseForExceptionEvent $event, $status) {
/* @var \Symfony\Component\HttpKernel\Exception\HttpException $exception */
$exception = $event
->getException();
$response = new ResourceResponse(new JsonApiDocumentTopLevel(new ErrorCollection([
$exception,
]), new NullIncludedData(), new LinkCollection([])), $exception
->getStatusCode(), $exception
->getHeaders());
$response
->addCacheableDependency($exception);
$event
->setResponse($response);
}