core/core.services.yml | 4 ++-- ...onSubscriber.php => FinalExceptionSubscriber.php} | 20 +++++++++++++++++--- ...iberTest.php => FinalExceptionSubscriberTest.php} | 8 ++++---- 3 files changed, 23 insertions(+), 9 deletions(-) diff --git a/core/core.services.yml b/core/core.services.yml index 40c6a8a..0c91b8c 100644 --- a/core/core.services.yml +++ b/core/core.services.yml @@ -1230,8 +1230,8 @@ services: tags: - { name: event_subscriber } arguments: ['@http_kernel', '@logger.channel.php', '@redirect.destination', '@router.no_access_checks'] - exception.default: - class: Drupal\Core\EventSubscriber\DefaultExceptionSubscriber + exception.final: + class: Drupal\Core\EventSubscriber\FinalExceptionSubscriber tags: - { name: event_subscriber } arguments: ['@config.factory'] diff --git a/core/lib/Drupal/Core/EventSubscriber/DefaultExceptionSubscriber.php b/core/lib/Drupal/Core/EventSubscriber/FinalExceptionSubscriber.php similarity index 86% rename from core/lib/Drupal/Core/EventSubscriber/DefaultExceptionSubscriber.php rename to core/lib/Drupal/Core/EventSubscriber/FinalExceptionSubscriber.php index 4d3bffc..2d6f022 100644 --- a/core/lib/Drupal/Core/EventSubscriber/DefaultExceptionSubscriber.php +++ b/core/lib/Drupal/Core/EventSubscriber/FinalExceptionSubscriber.php @@ -13,12 +13,25 @@ use Symfony\Component\HttpKernel\KernelEvents; /** - * Last-chance handler for exceptions. + * Last-chance handler for exceptions: the final exception subscriber. * * This handler will catch any exceptions not caught elsewhere and report * them as an error page. + * + * Each format has its own way of handling exceptions: + * - html: exception.default_html, exception.custom_page_html and + * exception.fast_404_html + * - json: exception.default_json + * + * And when the serialization module is installed, all serialization formats are + * handled by a single exception subscriber:: serialization.exception.default. + * + * This exception subscriber runs after all the above (it has a lower priority), + * which makes it the last-chance exception handler. It always sends a plain + * text response. If it's a displayable error and the error level is configured + * to be verbose, then a helpful backtrace is also printed. */ -class DefaultExceptionSubscriber implements EventSubscriberInterface { +class FinalExceptionSubscriber implements EventSubscriberInterface { use StringTranslationTrait; /** @@ -36,7 +49,7 @@ class DefaultExceptionSubscriber implements EventSubscriberInterface { protected $configFactory; /** - * Constructs a new DefaultExceptionSubscriber. + * Constructs a new FinalExceptionSubscriber. * * @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory * The configuration factory. @@ -129,6 +142,7 @@ public function onException(GetResponseForExceptionEvent $event) { * {@inheritdoc} */ public static function getSubscribedEvents() { + // Run as the final (very late) KernelEvents::EXCEPTION subscriber. $events[KernelEvents::EXCEPTION][] = ['onException', -256]; return $events; } diff --git a/core/tests/Drupal/Tests/Core/EventSubscriber/DefaultExceptionSubscriberTest.php b/core/tests/Drupal/Tests/Core/EventSubscriber/FinalExceptionSubscriberTest.php similarity index 87% rename from core/tests/Drupal/Tests/Core/EventSubscriber/DefaultExceptionSubscriberTest.php rename to core/tests/Drupal/Tests/Core/EventSubscriber/FinalExceptionSubscriberTest.php index a0a48a1..aaf6982 100644 --- a/core/tests/Drupal/Tests/Core/EventSubscriber/DefaultExceptionSubscriberTest.php +++ b/core/tests/Drupal/Tests/Core/EventSubscriber/FinalExceptionSubscriberTest.php @@ -2,7 +2,7 @@ namespace Drupal\Tests\Core\EventSubscriber; -use Drupal\Core\EventSubscriber\DefaultExceptionSubscriber; +use Drupal\Core\EventSubscriber\FinalExceptionSubscriber; use Drupal\Tests\UnitTestCase; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; @@ -11,10 +11,10 @@ use Symfony\Component\HttpKernel\HttpKernelInterface; /** - * @coversDefaultClass \Drupal\Core\EventSubscriber\DefaultExceptionSubscriber + * @coversDefaultClass \Drupal\Core\EventSubscriber\FinalExceptionSubscriber * @group EventSubscriber */ -class DefaultExceptionSubscriberTest extends UnitTestCase { +class FinalExceptionSubscriberTest extends UnitTestCase { /** * @covers ::onException @@ -41,7 +41,7 @@ public function testOnExceptionWithUnknownFormat() { } -class TestDefaultExceptionSubscriber extends DefaultExceptionSubscriber { +class TestDefaultExceptionSubscriber extends FinalExceptionSubscriber { protected function isErrorDisplayable($error) { return TRUE;