[HttpKernel][FrameworkBundle] Turn HTTP exceptions to HTTP status codes by default#27519
Conversation
5139ef9 to
d53ebbe
Compare
|
Status: needs review |
e6461da to
1c9fc7a
Compare
javiereguiluz
left a comment
There was a problem hiding this comment.
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(); |
There was a problem hiding this comment.
->getMockBuilder(HttpKernelInterface::class)->
| private $isTerminating = false; | ||
|
|
||
| public function __construct($controller, LoggerInterface $logger = null, $debug = false) | ||
| public function __construct($controller, LoggerInterface $logger = null, $debug = false, $charset = null, $fileLinkFormat = null) |
|
@nicolas-grekas thanks, would be cool if you would backport this to all affected versions (3.4, 4.x) |
1c9fc7a to
206be77
Compare
|
comments addressed thanks |
206be77 to
80b0739
Compare
|
more comments @symfony/deciders ? |
…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
| if (!$event->isMasterRequest()) { | ||
| return; | ||
| } | ||
| if (!$this->isTerminating) { |
There was a problem hiding this comment.
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.
This reverts PR symfony#27519 this commit 18c2dde, reversing changes made to ac1189a.
This reverts PR symfony#27519 this commit 18c2dde, reversing changes made to ac1189a.
…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
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.