Symfony 4 – Error 500 thrown instead of 403

  exception, symfony4

I’m running Symfony 4/5, and for all my controllers in order to be able to execute the method I have an EventSubscriber that checks for the right permissions.

If the user is not granted, then it throws an AccessDeniedHttpException.
This works fine as the method is binded to a route.
But when rendering inside a twig template manually a controller action as :

{{ render( controller(‘AppExampleBundleControllerChartsController::renderChart’ ) }}

I got a 500 error instead of a 403.

I’ve debugged the app and checked that the exception as actually thrown, but the browser shows a 500 exception.

Is this a bug, or do I have to handle in another way the exception when it is for manually rendered methods from a twig template ?

Source: Symfony4 Questions