Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[HttpKernel][FrameworkBundle] Turn HTTP exceptions to HTTP status codes by default #27519

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
Jul 7, 2018

Conversation

nicolas-grekas
Copy link
Member

@nicolas-grekas nicolas-grekas commented Jun 6, 2018

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

When an exception is thrown, if it is not handled then it will be reinjected as a 2nd exception event via HttpKernel::terminateWithException(). When this happens, this will generate a proper HTTP status code.

@nicolas-grekas
Copy link
Member Author

Status: needs review

Copy link
Member

@javiereguiluz javiereguiluz left a comment

Choose a reason for hiding this comment

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

I haven't tested it in a real app, but the code looks OK to me.

public function testNullController()
{
$listener = new ExceptionListener(null);
$kernel = $this->getMockBuilder('Symfony\Component\HttpKernel\HttpKernelInterface')->getMock();
Copy link
Member

Choose a reason for hiding this comment

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

->getMockBuilder(HttpKernelInterface::class)->


public function __construct($controller, LoggerInterface $logger = null, $debug = false)
public function __construct($controller, LoggerInterface $logger = null, $debug = false, $charset = null, $fileLinkFormat = null)
Copy link
Member

Choose a reason for hiding this comment

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

string $charset = null

@dominikzogg
Copy link

@nicolas-grekas thanks, would be cool if you would backport this to all affected versions (3.4, 4.x)

@nicolas-grekas
Copy link
Member Author

comments addressed thanks

@nicolas-grekas
Copy link
Member Author

more comments @symfony/deciders ?

@nicolas-grekas nicolas-grekas merged commit 80b0739 into symfony:master Jul 7, 2018
nicolas-grekas added a commit that referenced this pull request Jul 7, 2018
…HTTP status codes by default (nicolas-grekas)

This PR was merged into the 4.2-dev branch.

Discussion
----------

[HttpKernel][FrameworkBundle] Turn HTTP exceptions to HTTP status codes by default

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

When an exception is thrown, *if it is not handled* then it will be reinjected as a 2nd exception event via `HttpKernel::terminateWithException()`. When this happens, this will generate a proper HTTP status code.

Commits
-------

80b0739 [HttpKernel][FrameworkBundle] Turn HTTP exceptions to HTTP status codes by default
@nicolas-grekas nicolas-grekas deleted the kernel-http-x branch July 7, 2018 16:05
if (!$event->isMasterRequest()) {
return;
}
if (!$this->isTerminating) {
Copy link
Member Author

@nicolas-grekas nicolas-grekas Jun 5, 2019

Choose a reason for hiding this comment

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

for the record, the state managed by this property ensures that we don't break apps that handle exceptions outside of the stack:

try {
    $kernel->handle($request);
} catch (SomeException $e) {
    // ...
}

as required e.g. in some framework migration strategies.
As hinted in the PR description, this allows running the fallback exception logic only when no catch block stopped the bubbling, in terminateWithException.

nicolas-grekas added a commit to nicolas-grekas/symfony that referenced this pull request Jun 5, 2019
This reverts PR symfony#27519 this commit 18c2dde,
reversing changes made to ac1189a.
nicolas-grekas added a commit to nicolas-grekas/symfony that referenced this pull request Jun 5, 2019
This reverts PR symfony#27519 this commit 18c2dde,
reversing changes made to ac1189a.
fabpot added a commit that referenced this pull request Jun 5, 2019
…las-grekas)

This PR was merged into the 4.2 branch.

Discussion
----------

[HttpKernel] Fix handling non-catchable fatal errors

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

This reverts PR #27519 this commit 18c2dde,
reversing changes made to ac1189a.

Right now, the listener is skipped on fatal errors.

Commits
-------

a1619cc [HttpKernel] Fix handling non-catchable fatal errors
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.

6 participants