diff --git a/src/Symfony/Component/HttpKernel/CHANGELOG.md b/src/Symfony/Component/HttpKernel/CHANGELOG.md index f64905cbe086e..4176eb0f515b3 100644 --- a/src/Symfony/Component/HttpKernel/CHANGELOG.md +++ b/src/Symfony/Component/HttpKernel/CHANGELOG.md @@ -4,6 +4,7 @@ CHANGELOG 4.1.0 ----- + * create `Reponse` objects for unhandled `HttpExceptionInterface` instead of throwing them * added orphaned events support to `EventDataCollector` * `ExceptionListener` now logs and collects exceptions at priority `2048` (previously logged at `-128` and collected at `0`) * Deprecated `service:action` syntax with a single colon to reference controllers. Use `service::method` instead. diff --git a/src/Symfony/Component/HttpKernel/HttpKernel.php b/src/Symfony/Component/HttpKernel/HttpKernel.php index d4ef09e8478ff..f0795fffd80e6 100644 --- a/src/Symfony/Component/HttpKernel/HttpKernel.php +++ b/src/Symfony/Component/HttpKernel/HttpKernel.php @@ -221,14 +221,17 @@ private function handleException(\Exception $e, Request $request, int $type): Re // a listener might have replaced the exception $e = $event->getException(); - if (!$event->hasResponse()) { + if ($event->hasResponse()) { + $response = $event->getResponse(); + } elseif ($e instanceof HttpExceptionInterface) { + $code = $e->getStatusCode(); + $response = new Response(isset(Response::$statusTexts[$code]) ? $code.' '.Response::$statusTexts[$code] : $code); + } else { $this->finishRequest($request, $type); throw $e; } - $response = $event->getResponse(); - // the developer asked for a specific status code if (!$event->isAllowingCustomResponseCode() && !$response->isClientError() && !$response->isServerError() && !$response->isRedirect()) { // ensure that we actually have an error response diff --git a/src/Symfony/Component/HttpKernel/Tests/HttpKernelTest.php b/src/Symfony/Component/HttpKernel/Tests/HttpKernelTest.php index 0adef984c6f5c..e39c3b64f4016 100644 --- a/src/Symfony/Component/HttpKernel/Tests/HttpKernelTest.php +++ b/src/Symfony/Component/HttpKernel/Tests/HttpKernelTest.php @@ -159,15 +159,15 @@ public function testHandleWhenAListenerReturnsAResponse() $this->assertEquals('hello', $kernel->handle(new Request())->getContent()); } - /** - * @expectedException \Symfony\Component\HttpKernel\Exception\NotFoundHttpException - */ public function testHandleWhenNoControllerIsFound() { $dispatcher = new EventDispatcher(); $kernel = $this->getHttpKernel($dispatcher, false); - $kernel->handle(new Request()); + $response = $kernel->handle(new Request()); + + $this->assertSame(404, $response->getStatusCode()); + $this->assertSame('404 Not Found', $response->getContent()); } public function testHandleWhenTheControllerIsAClosure() pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy