Mercurial > hg > isophonics-drupal-site
view core/lib/Drupal/Core/EventSubscriber/ExceptionJsonSubscriber.php @ 13:5fb285c0d0e3
Update Drupal core to 8.4.7 via Composer. Security update; I *think* we've
been lucky to get away with this so far, as we don't support self-registration
which seems to be used by the so-called "drupalgeddon 2" attack that 8.4.5
was vulnerable to.
author | Chris Cannam |
---|---|
date | Mon, 23 Apr 2018 09:33:26 +0100 |
parents | 4c8ae668cc8c |
children | 1fec387a4317 |
line wrap: on
line source
<?php namespace Drupal\Core\EventSubscriber; use Symfony\Component\HttpFoundation\JsonResponse; use Symfony\Component\HttpKernel\Event\GetResponseForExceptionEvent; /** * Default handling for JSON errors. */ class ExceptionJsonSubscriber extends HttpExceptionSubscriberBase { /** * {@inheritdoc} */ protected function getHandledFormats() { return ['json', 'drupal_modal', 'drupal_dialog', 'drupal_ajax']; } /** * {@inheritdoc} */ protected static function getPriority() { // This will fire after the most common HTML handler, since HTML requests // are still more common than JSON requests. return -75; } /** * Handles all 4xx errors for JSON. * * @param \Symfony\Component\HttpKernel\Event\GetResponseForExceptionEvent $event * The event to process. */ public function on4xx(GetResponseForExceptionEvent $event) { /** @var \Symfony\Component\HttpKernel\Exception\HttpExceptionInterface $exception */ $exception = $event->getException(); $response = new JsonResponse(['message' => $event->getException()->getMessage()], $exception->getStatusCode(), $exception->getHeaders()); $event->setResponse($response); } }