Skip to content

Navigation Menu

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

[HttpKernel] Turn HTTP exceptions to responses on terminateWithException() #27505

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion 3 src/Symfony/Bundle/FrameworkBundle/Resources/config/web.xml
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,9 @@
</service>

<service id="http_exception_listener" class="Symfony\Component\HttpKernel\EventListener\ExceptionListener">
<tag name="kernel.event_listener" event="kernel.exception" method="onKernelException" priority="-256"/>
<tag name="kernel.event_listener" event="kernel.exception" method="onKernelException" priority="-2048" />
<tag name="monolog.logger" channel="request" />
<tag name="kernel.reset" method="reset" />
<argument>null</argument>
<argument type="service" id="logger" on-invalid="null" />
<argument>%kernel.debug%</argument>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ class ExceptionListener implements EventSubscriberInterface
protected $debug;
private $charset;
private $fileLinkFormat;
private $isTerminating = false;

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

public function onKernelException(GetResponseForExceptionEvent $event)
{
if (null === $this->controller) {
if (!$event->isMasterRequest()) {
return;
}
if (!$this->isTerminating) {
$this->isTerminating = true;

return;
}
$this->isTerminating = false;
}
$exception = $event->getException();
$request = $event->getRequest();
$eventDispatcher = func_num_args() > 2 ? func_get_arg(2) : null;
Expand Down Expand Up @@ -88,6 +100,11 @@ public function onKernelException(GetResponseForExceptionEvent $event)
}
}

public function reset()
{
$this->isTerminating = false;
}

public static function getSubscribedEvents()
{
return array(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,9 @@ public function testNullController()
$event = new GetResponseForExceptionEvent($kernel, $request, HttpKernelInterface::MASTER_REQUEST, new \Exception('foo'));

$listener->onKernelException($event);
$this->assertNull($event->getResponse());

$listener->onKernelException($event);
$this->assertContains('Whoops, looks like something went wrong.', $event->getResponse()->getContent());
}
}
Expand Down
Morty Proxy This is a proxified and sanitized view of the page, visit original site.