diff --git a/core/lib/Drupal/Core/Form/EventSubscriber/FormAjaxSubscriber.php b/core/lib/Drupal/Core/Form/EventSubscriber/FormAjaxSubscriber.php index 054e262..ffbd8f3 100644 --- a/core/lib/Drupal/Core/Form/EventSubscriber/FormAjaxSubscriber.php +++ b/core/lib/Drupal/Core/Form/EventSubscriber/FormAjaxSubscriber.php @@ -79,12 +79,12 @@ public function onException(GetResponseForExceptionEvent $event) { protected function getFormAjaxException(\Exception $e) { $exception = NULL; while ($e) { - if (!$e instanceof FormAjaxException) { - $e = $e->getPrevious(); + if ($e instanceof FormAjaxException) { + $exception = $e; + break; } - $exception = $e; - break; + $e = $e->getPrevious(); } return $exception; } diff --git a/core/tests/Drupal/Tests/Core/Form/EventSubscriber/FormAjaxSubscriberTest.php b/core/tests/Drupal/Tests/Core/Form/EventSubscriber/FormAjaxSubscriberTest.php index bd645f6..eb01501 100644 --- a/core/tests/Drupal/Tests/Core/Form/EventSubscriber/FormAjaxSubscriberTest.php +++ b/core/tests/Drupal/Tests/Core/Form/EventSubscriber/FormAjaxSubscriberTest.php @@ -159,6 +159,20 @@ public function testOnExceptionNestedException() { } /** + * @covers ::getFormAjaxException + */ + public function testOnExceptionNestedWrongException() { + $nested_exception = new \Exception(); + $exception = new \Exception('', 0, $nested_exception); + $request = new Request(); + + $this->formAjaxResponseBuilder->expects($this->never()) + ->method('buildResponse'); + + $this->assertResponseFromException($request, $exception, NULL); + } + + /** * Asserts that the expected response is derived from the given exception. * * @param \Symfony\Component\HttpFoundation\Request $request