.../EventSubscriber/DefaultExceptionSubscriber.php | 50 ++-------------------- .../Comment/CommentResourceTestBase.php | 2 +- .../DefaultExceptionSubscriberTest.php | 1 - 3 files changed, 4 insertions(+), 49 deletions(-) diff --git a/core/lib/Drupal/Core/EventSubscriber/DefaultExceptionSubscriber.php b/core/lib/Drupal/Core/EventSubscriber/DefaultExceptionSubscriber.php index 7b57933..fdc2385 100644 --- a/core/lib/Drupal/Core/EventSubscriber/DefaultExceptionSubscriber.php +++ b/core/lib/Drupal/Core/EventSubscriber/DefaultExceptionSubscriber.php @@ -7,7 +7,6 @@ use Drupal\Core\StringTranslation\StringTranslationTrait; use Drupal\Core\Utility\Error; use Symfony\Component\EventDispatcher\EventSubscriberInterface; -use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpKernel\Event\GetResponseForExceptionEvent; use Symfony\Component\HttpKernel\Exception\HttpExceptionInterface; @@ -59,12 +58,12 @@ protected function getErrorLevel() { } /** - * Handles any exception as a generic error page for HTML. + * Handles exceptions for this subscriber. * * @param \Symfony\Component\HttpKernel\Event\GetResponseForExceptionEvent $event * The event to process. */ - protected function onHtml(GetResponseForExceptionEvent $event) { + public function onException(GetResponseForExceptionEvent $event) { $exception = $event->getException(); $error = Error::decodeException($exception); @@ -132,50 +131,7 @@ protected function onHtml(GetResponseForExceptionEvent $event) { } /** - * Handles an HttpExceptionInterface exception for unknown formats. - * - * @param \Symfony\Component\HttpKernel\Event\GetResponseForExceptionEvent $event - * The event to process. - */ - protected function onFormatUnknown(GetResponseForExceptionEvent $event) { - /** @var \Symfony\Component\HttpKernel\Exception\HttpExceptionInterface|\Exception $exception */ - $exception = $event->getException(); - - $response = new Response($exception->getMessage(), $exception->getStatusCode(), $exception->getHeaders()); - $event->setResponse($response); - } - - /** - * Handles errors for this subscriber. - * - * @param \Symfony\Component\HttpKernel\Event\GetResponseForExceptionEvent $event - * The event to process. - */ - public function onException(GetResponseForExceptionEvent $event) { - $format = $event->getRequest()->getRequestFormat(); - $exception = $event->getException(); - - $method = 'on' . $format; - if (!method_exists($this, $method)) { - if ($exception instanceof HttpExceptionInterface) { - $this->onFormatUnknown($event); - $response = $event->getResponse(); - $response->headers->set('Content-Type', 'text/plain'); - } - else { - $this->onHtml($event); - } - } - else { - $this->$method($event); - } - } - - /** - * Registers the methods in this class that should be listeners. - * - * @return array - * An array of event listener definitions. + * {@inheritdoc} */ public static function getSubscribedEvents() { $events[KernelEvents::EXCEPTION][] = ['onException', -256]; diff --git a/core/modules/rest/tests/src/Functional/EntityResource/Comment/CommentResourceTestBase.php b/core/modules/rest/tests/src/Functional/EntityResource/Comment/CommentResourceTestBase.php index b04da54..223a1ee 100644 --- a/core/modules/rest/tests/src/Functional/EntityResource/Comment/CommentResourceTestBase.php +++ b/core/modules/rest/tests/src/Functional/EntityResource/Comment/CommentResourceTestBase.php @@ -281,7 +281,7 @@ public function testPostDxWithoutCriticalBaseFields() { // @todo Uncomment, remove next 3 lines in https://www.drupal.org/node/2820364. $this->assertSame(500, $response->getStatusCode()); $this->assertSame(['text/plain; charset=UTF-8'], $response->getHeader('Content-Type')); - $this->assertSame('Internal Server Error', (string) $response->getBody()); + $this->assertStringStartsWith('The website encountered an unexpected error. Please try again later.

Symfony\Component\HttpKernel\Exception\HttpException: Internal Server Error in Drupal\rest\Plugin\rest\resource\EntityResource->post()', (string) $response->getBody()); //$this->assertResourceErrorResponse(422, "Unprocessable Entity: validation failed.\nentity_type: This value should not be null.\n", $response); // DX: 422 when missing 'entity_id' field. diff --git a/core/tests/Drupal/Tests/Core/EventSubscriber/DefaultExceptionSubscriberTest.php b/core/tests/Drupal/Tests/Core/EventSubscriber/DefaultExceptionSubscriberTest.php index 6582500..279d830 100644 --- a/core/tests/Drupal/Tests/Core/EventSubscriber/DefaultExceptionSubscriberTest.php +++ b/core/tests/Drupal/Tests/Core/EventSubscriber/DefaultExceptionSubscriberTest.php @@ -18,7 +18,6 @@ class DefaultExceptionSubscriberTest extends UnitTestCase { /** * @covers ::onException - * @covers ::onFormatUnknown */ public function testOnExceptionWithUnknownFormat() { $config_factory = $this->getConfigFactoryStub();