diff --git a/core/lib/Drupal/Core/EventSubscriber/ExceptionJsonSubscriber.php b/core/lib/Drupal/Core/EventSubscriber/ExceptionJsonSubscriber.php index 58c678b..3f4b207 100644 --- a/core/lib/Drupal/Core/EventSubscriber/ExceptionJsonSubscriber.php +++ b/core/lib/Drupal/Core/EventSubscriber/ExceptionJsonSubscriber.php @@ -28,13 +28,15 @@ protected static function getPriority() { } /** - * Handles all 4XYs errors for JSON. + * Handles all 400 errors for JSON. * * @param \Symfony\Component\HttpKernel\Event\GetResponseForExceptionEvent $event * The event to process. */ - public function on4XY(GetResponseForExceptionEvent $event) { - $response = new JsonResponse(array('message' => $event->getException()->getMessage()), Response::HTTP_FORBIDDEN); + public function on400(GetResponseForExceptionEvent $event) { + /** @var \Symfony\Component\HttpKernel\Exception\HttpExceptionInterface $exception */ + $exception = $event->getException(); + $response = new JsonResponse(array('message' => $event->getException()->getMessage()), $exception->getStatusCode()); $event->setResponse($response); } diff --git a/core/lib/Drupal/Core/EventSubscriber/HttpExceptionSubscriberBase.php b/core/lib/Drupal/Core/EventSubscriber/HttpExceptionSubscriberBase.php index a9e022f..6d4555d 100644 --- a/core/lib/Drupal/Core/EventSubscriber/HttpExceptionSubscriberBase.php +++ b/core/lib/Drupal/Core/EventSubscriber/HttpExceptionSubscriberBase.php @@ -90,7 +90,9 @@ public function onException(GetResponseForExceptionEvent $event) { if ($exception instanceof HttpExceptionInterface && (empty($handled_formats) || in_array($format, $handled_formats))) { $method = 'on' . $exception->getStatusCode(); - $method_fallback = 'on' . (string) (int) ($exception->getStatusCode() / 100) . 'XY'; + // Keep just the leading number of the status code to produce either a + // on400 or a 500 method callback. + $method_fallback = 'on' . (int) ($exception->getStatusCode() / 100) . '00'; // We want to allow the method to be called and still not set a response // if it has additional filtering logic to determine when it will apply. // It is therefore the method's responsibility to set the response on the