Skip to content

[HttpKernel] Handle NoConfigurationException "onKernelException()" #27227

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

Merged
merged 1 commit into from
May 11, 2018
Merged
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
19 changes: 13 additions & 6 deletions src/Symfony/Component/HttpKernel/EventListener/RouterListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use Psr\Log\LoggerInterface;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Event\GetResponseEvent;
use Symfony\Component\HttpKernel\Event\GetResponseForExceptionEvent;
use Symfony\Component\HttpKernel\Event\FinishRequestEvent;
use Symfony\Component\HttpKernel\Kernel;
use Symfony\Component\HttpKernel\KernelEvents;
Expand Down Expand Up @@ -129,12 +130,6 @@ public function onKernelRequest(GetResponseEvent $event)
unset($parameters['_route'], $parameters['_controller']);
$request->attributes->set('_route_params', $parameters);
} catch (ResourceNotFoundException $e) {
if ($this->debug && $e instanceof NoConfigurationException) {
$event->setResponse($this->createWelcomeResponse());

return;
}

$message = sprintf('No route found for "%s %s"', $request->getMethod(), $request->getPathInfo());

if ($referer = $request->headers->get('referer')) {
Expand All @@ -149,11 +144,23 @@ public function onKernelRequest(GetResponseEvent $event)
}
}

public function onKernelException(GetResponseForExceptionEvent $event)
{
if (!$this->debug || !($e = $event->getException()) instanceof NotFoundHttpException) {
return;
}

if ($e->getPrevious() instanceof NoConfigurationException) {
$event->setResponse($this->createWelcomeResponse());
}
}

public static function getSubscribedEvents()
{
return array(
KernelEvents::REQUEST => array(array('onKernelRequest', 32)),
KernelEvents::FINISH_REQUEST => array(array('onKernelFinishRequest', 0)),
KernelEvents::EXCEPTION => array('onKernelException', -64),
);
}

Expand Down