Mercurial > hg > isophonics-drupal-site
comparison core/lib/Drupal/Core/EventSubscriber/ExceptionJsonSubscriber.php @ 14:1fec387a4317
Update Drupal core to 8.5.2 via Composer
author | Chris Cannam |
---|---|
date | Mon, 23 Apr 2018 09:46:53 +0100 |
parents | 4c8ae668cc8c |
children |
comparison
equal
deleted
inserted
replaced
13:5fb285c0d0e3 | 14:1fec387a4317 |
---|---|
1 <?php | 1 <?php |
2 | 2 |
3 namespace Drupal\Core\EventSubscriber; | 3 namespace Drupal\Core\EventSubscriber; |
4 | 4 |
5 use Drupal\Core\Cache\CacheableDependencyInterface; | |
6 use Drupal\Core\Cache\CacheableJsonResponse; | |
5 use Symfony\Component\HttpFoundation\JsonResponse; | 7 use Symfony\Component\HttpFoundation\JsonResponse; |
6 use Symfony\Component\HttpKernel\Event\GetResponseForExceptionEvent; | 8 use Symfony\Component\HttpKernel\Event\GetResponseForExceptionEvent; |
7 | 9 |
8 /** | 10 /** |
9 * Default handling for JSON errors. | 11 * Default handling for JSON errors. |
33 * The event to process. | 35 * The event to process. |
34 */ | 36 */ |
35 public function on4xx(GetResponseForExceptionEvent $event) { | 37 public function on4xx(GetResponseForExceptionEvent $event) { |
36 /** @var \Symfony\Component\HttpKernel\Exception\HttpExceptionInterface $exception */ | 38 /** @var \Symfony\Component\HttpKernel\Exception\HttpExceptionInterface $exception */ |
37 $exception = $event->getException(); | 39 $exception = $event->getException(); |
38 $response = new JsonResponse(['message' => $event->getException()->getMessage()], $exception->getStatusCode(), $exception->getHeaders()); | 40 |
41 // If the exception is cacheable, generate a cacheable response. | |
42 if ($exception instanceof CacheableDependencyInterface) { | |
43 $response = new CacheableJsonResponse(['message' => $event->getException()->getMessage()], $exception->getStatusCode(), $exception->getHeaders()); | |
44 $response->addCacheableDependency($exception); | |
45 } | |
46 else { | |
47 $response = new JsonResponse(['message' => $event->getException()->getMessage()], $exception->getStatusCode(), $exception->getHeaders()); | |
48 } | |
49 | |
39 $event->setResponse($response); | 50 $event->setResponse($response); |
40 } | 51 } |
41 | 52 |
42 } | 53 } |