diff --git a/core/lib/Drupal/Core/EventSubscriber/DefaultExceptionSubscriber.php b/core/lib/Drupal/Core/EventSubscriber/DefaultExceptionSubscriber.php index 4bacbbf..ba0418b 100644 --- a/core/lib/Drupal/Core/EventSubscriber/DefaultExceptionSubscriber.php +++ b/core/lib/Drupal/Core/EventSubscriber/DefaultExceptionSubscriber.php @@ -122,6 +122,7 @@ protected function onHtml(GetResponseForExceptionEvent $event) { $content = $this->t('The website encountered an unexpected error. Please try again later.'); $content .= $message ? '

' . $message : ''; $response = new CacheableResponse($content, 500); + $response->prepare($event->getRequest()); // Persist any cacheability metadata. if ($exception instanceof CacheableHttpExceptionInterface) { @@ -159,6 +160,7 @@ protected function onJson(GetResponseForExceptionEvent $event) { } $response = new CacheableJsonResponse($data, Response::HTTP_INTERNAL_SERVER_ERROR); + $response->prepare($event->getRequest()); // Persist any cacheability metadata. if ($exception instanceof CacheableHttpExceptionInterface) { @@ -184,6 +186,7 @@ protected function onFormatUnknown(GetResponseForExceptionEvent $event) { $exception = $event->getException(); $response = new CacheableResponse($exception->getMessage(), $exception->getStatusCode(), $exception->getHeaders()); + $response->prepare($event->getRequest()); // Persist any cacheability metadata. if ($exception instanceof CacheableHttpExceptionInterface) { diff --git a/core/lib/Drupal/Core/EventSubscriber/ExceptionJsonSubscriber.php b/core/lib/Drupal/Core/EventSubscriber/ExceptionJsonSubscriber.php index bf27f2f..92fb309 100644 --- a/core/lib/Drupal/Core/EventSubscriber/ExceptionJsonSubscriber.php +++ b/core/lib/Drupal/Core/EventSubscriber/ExceptionJsonSubscriber.php @@ -110,6 +110,7 @@ public function on415(GetResponseForExceptionEvent $event) { protected function setEventResponse(GetResponseForExceptionEvent $event, $status) { $exception = $event->getException(); $response = new CacheableJsonResponse(['message' => $exception->getMessage()], $status); + $response->prepare($event->getRequest()); // Persist any cacheability metadata. if ($exception instanceof CacheableHttpExceptionInterface) { diff --git a/core/modules/serialization/src/EventSubscriber/DefaultExceptionSubscriber.php b/core/modules/serialization/src/EventSubscriber/DefaultExceptionSubscriber.php index 0f62752..39eedc3 100644 --- a/core/modules/serialization/src/EventSubscriber/DefaultExceptionSubscriber.php +++ b/core/modules/serialization/src/EventSubscriber/DefaultExceptionSubscriber.php @@ -148,10 +148,12 @@ public function on429(GetResponseForExceptionEvent $event) { */ protected function setEventResponse(GetResponseForExceptionEvent $event, $status) { $exception = $event->getException(); - $format = $event->getRequest()->getRequestFormat(); + $request = $event->getRequest(); + $format = $request->getRequestFormat(); $content = ['message' => $exception->getMessage()]; $encoded_content = $this->serializer->serialize($content, $format); $response = new CacheableResponse($encoded_content, $status); + $response->prepare($request); // Persist any cacheability metadata. if ($exception instanceof CacheableHttpExceptionInterface) {