Skip to content
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

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

Closed
wants to merge 1 commit into from

Conversation

nicolas-grekas
Copy link
Member

Q A
Branch? 3.4
Bug fix? yes
New feature? no
BC breaks? no
Deprecations? no
Tests pass? yes
Fixed tickets #27212
License MIT
Doc PR -

#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 for NotFoundHttpException) while allowing ppl that have custom listeners or try/catch to keep things working as previously.

@@ -49,6 +49,15 @@ public function __construct($controller, LoggerInterface $logger = null, $debug

public function onKernelException(GetResponseForExceptionEvent $event)
{
while (null === $this->controller) {
Copy link
Member

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.

Copy link
Member Author

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 :)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

while removed btw :)

@nicolas-grekas nicolas-grekas force-pushed the kernel-http-x branch 2 times, most recently from b9b3a8f to 76d532e Compare June 5, 2018 13:33
@@ -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) {
Copy link
Member

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.

Copy link
Member Author

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.

@nicolas-grekas
Copy link
Member Author

Let's revert instead, see #27516
I'll reopen on master.

@nicolas-grekas nicolas-grekas deleted the kernel-http-x branch June 6, 2018 09:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants