Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit d5c882f

Browse filesBrowse files
[HttpKernel] Turn HTTP exceptions to responses on terminateWithException()
1 parent 9a077ca commit d5c882f
Copy full SHA for d5c882f

File tree

Expand file treeCollapse file tree

3 files changed

+21
-1
lines changed
Filter options
Expand file treeCollapse file tree

3 files changed

+21
-1
lines changed

‎src/Symfony/Bundle/FrameworkBundle/Resources/config/web.xml

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/FrameworkBundle/Resources/config/web.xml
+2-1Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,9 @@
6868
</service>
6969

7070
<service id="http_exception_listener" class="Symfony\Component\HttpKernel\EventListener\ExceptionListener">
71-
<tag name="kernel.event_listener" event="kernel.exception" method="onKernelException" priority="-256"/>
71+
<tag name="kernel.event_listener" event="kernel.exception" method="onKernelException" priority="-2048" />
7272
<tag name="monolog.logger" channel="request" />
73+
<tag name="kernel.reset" method="reset" />
7374
<argument>null</argument>
7475
<argument type="service" id="logger" on-invalid="null" />
7576
<argument>%kernel.debug%</argument>

‎src/Symfony/Component/HttpKernel/EventListener/ExceptionListener.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/HttpKernel/EventListener/ExceptionListener.php
+17Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ class ExceptionListener implements EventSubscriberInterface
3737
protected $debug;
3838
private $charset;
3939
private $fileLinkFormat;
40+
private $isTerminating = false;
4041

4142
public function __construct($controller, LoggerInterface $logger = null, $debug = false, $charset = null, $fileLinkFormat = null)
4243
{
@@ -49,6 +50,17 @@ public function __construct($controller, LoggerInterface $logger = null, $debug
4950

5051
public function onKernelException(GetResponseForExceptionEvent $event)
5152
{
53+
if (null === $this->controller) {
54+
if (!$event->isMasterRequest()) {
55+
return;
56+
}
57+
if (!$this->isTerminating) {
58+
$this->isTerminating = true;
59+
60+
return;
61+
}
62+
$this->isTerminating = false;
63+
}
5264
$exception = $event->getException();
5365
$request = $event->getRequest();
5466
$eventDispatcher = func_num_args() > 2 ? func_get_arg(2) : null;
@@ -88,6 +100,11 @@ public function onKernelException(GetResponseForExceptionEvent $event)
88100
}
89101
}
90102

103+
public function reset()
104+
{
105+
$this->isTerminating = false;
106+
}
107+
91108
public static function getSubscribedEvents()
92109
{
93110
return array(

‎src/Symfony/Component/HttpKernel/Tests/EventListener/ExceptionListenerTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/HttpKernel/Tests/EventListener/ExceptionListenerTest.php
+2Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,9 @@ public function testNullController()
165165
$event = new GetResponseForExceptionEvent($kernel, $request, HttpKernelInterface::MASTER_REQUEST, new \Exception('foo'));
166166

167167
$listener->onKernelException($event);
168+
$this->assertNull($event->getResponse());
168169

170+
$listener->onKernelException($event);
169171
$this->assertContains('Whoops, looks like something went wrong.', $event->getResponse()->getContent());
170172
}
171173
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.