Commit 8aa9807a authored by Fabien Potencier's avatar Fabien Potencier

fixed exception handling when an exception is thrown in the before filter (closes #260)

parent c959ea3f
......@@ -550,7 +550,12 @@ class Application extends \Pimple implements HttpKernelInterface, EventSubscribe
{
if (!$this->beforeDispatched) {
$this->beforeDispatched = true;
try {
$this['dispatcher']->dispatch(SilexEvents::BEFORE, $event);
} catch (\Exception $e) {
// as we are already handling an exception, ignore this one
// even if it might have been thrown on purpose by the developer
}
}
$errorEvent = new GetResponseForErrorEvent($this, $event->getRequest(), $event->getRequestType(), $event->getException());
......
......@@ -163,7 +163,18 @@ class BeforeAfterFilterTest extends \PHPUnit_Framework_TestCase
$this->assertEquals(2, $i);
}
public function testRequestShouldBePopulatedOnBefore() {
public function testBeforeFilterExceptionsWhenHandlingAnException()
{
$app = new Application();
$app->before(function () { throw new \RuntimeException(''); });
// even if the before filter throws an exception, we must have the 404
$this->assertEquals(404, $app->handle(Request::create('/'))->getStatusCode());
}
public function testRequestShouldBePopulatedOnBefore()
{
$app = new Application();
$app->before(function () use ($app) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment