fabpot/Silex — Issue #260: "before" filter (possibly erroniously) called when handling Exception
Author: chrismsnz
Created: 2012-02-22 01:48:06+00:00
State: open

Hi,

I've run into an issue with Silex and was just wondering if I could get some guidance on whether this is intended behavior or not before I try and work around it.

In my application, I have a before filter that checks a few parameters on the request and will throw an exception if it detects anything wrong and a custom error handler takes these errors and renders them as a JSON response with an appropriate HTTP code.

However, if Silex is already handling an error internally (e.g. client requests a route that doesn't exist) it proceeds to call my before filter and if that happens to throw an exception, it bubbles all the way up to the top (bypassing my handler and the silex debug handler) and results in a Fatal Error, uncaught exception.

Here is a very small application that illustrates the issue:

```php
before(function (Request $r) {
throw new Exception('Uncaught!');
});

$app->error(function (Exception $e, $code) {
return new \Symfony\Component\HttpFoundation\Response('Something happened', 400);
});

$app->run();
```

If this application is served and the client requests `/` I would expect to see the before filter bypassed and the error handler called. If the application was running in debug mode and the error handler was removed, I would expect to see the pretty debug representation of the exception.

If I'm doing it wrong, please feel free to point it out. I did ask on the #symfony channel but nobody was really around to help.

Cheers,
Chris.