-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[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
Conversation
@@ -49,6 +49,15 @@ public function __construct($controller, LoggerInterface $logger = null, $debug | |||
|
|||
public function onKernelException(GetResponseForExceptionEvent $event) | |||
{ | |||
while (null === $this->controller) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should be a if
rather than a while
. It would be much easier to understand, and it can never loop anyway.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
using while
allows using the break
below :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
while removed btw :)
b9b3a8f
to
76d532e
Compare
@@ -49,6 +49,19 @@ public function __construct($controller, LoggerInterface $logger = null, $debug | |||
|
|||
public function onKernelException(GetResponseForExceptionEvent $event) | |||
{ | |||
if (null === $this->controller) { | |||
$terminating = false; | |||
foreach (debug_backtrace() as $frame) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm very much against this kind of code.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree, I lacked a better idea, but this is fixed now.
76d532e
to
d5c882f
Compare
Let's revert instead, see #27516 |
#26138 introduced a BC break that is described in the linked issue.
In order to fix it, I propose to postpone generating a response for HTTP exceptions to the exception event that is throw in
terminateWithException()
. This allows providing the target DX (generate 404 forNotFoundHttpException
) while allowing ppl that have custom listeners or try/catch to keep things working as previously.