FriendsOfSymfony / FOSRestBundle

This Bundle provides various tools to rapidly develop RESTful API's with Symfony
http://symfony.com/doc/master/bundles/FOSRestBundle/index.html
MIT License
2.79k stars 704 forks source link

Question: Add Exception Trace to Response Content #2304

Open kirkbaly opened 3 years ago

kirkbaly commented 3 years ago

Is there a way to add full stack traces to the JSON response content for exceptions? I am using JMS Serializer and have played around with a few different options but I haven't found a reliable way that doesn't rely on the internal classes of FOSRestBundle but also maintains the status code and message mapping that is being performed in \FOS\RestBundle\Serializer\Normalizer\FlattenExceptionHandler.

The cleanest way to do this without changes to FlattenExceptionHandler would be to implement a JMS Serializer post_serializer event, but JMS Serializer doesn't fire the post_serializer event for custom handlers.

One option would be to add a new configuration option for this. Something like:

fos_rest:
    exception:
        show_trace: "%kernel.debug%"

This would be easy enough to implement in \FOS\RestBundle\Serializer\Normalizer\FlattenExceptionHandler and \FOS\RestBundle\Serializer\Normalizer\FlattenExceptionNormalizer.

Any assistance or thoughts would be greatly appreciated.