2

I used to configure the FOSRestBundle 1.7 exception wrapper handler like it's described in the documentation : http://symfony.com/doc/1.7/bundles/FOSRestBundle/4-exception-controller-support.html I'm doing this in order to display Exception with my own format. Example :

app/config/config.yml :

fos_rest:
    view:
        exception_handler: AppBundle\Handler\ExceptionWrapperHandler

src/AppBundle/Handler/ExceptionWrapperHandler.php :

namespace AppBundle\Handler;

use FOS\RestBundle\View\ExceptionWrapperHandlerInterface;

class ExceptionWrapperHandler implements ExceptionWrapperHandlerInterface
{
    public function wrap($data)
    {
        $exception = $data['exception'];

        return array(
            'code'    => $exception->getCode(),
            'message' => $exception->getMessage()
        );
    }
}

But when I switched to FOSRestBundle 2.0 version it's not as easy and if I understand right, they advice to use the JMS Serializer handlers. I did not find how to configure it. Can someone please help me on this problem ?

Masacc
  • 106
  • 8
  • would be interested in that as well, current documentation only shows a way how to achieve that with symfony normalizers instead of JMS: https://github.com/FriendsOfSymfony/FOSRestBundle/blob/master/UPGRADING-2.0.md – LBA Oct 07 '16 at 09:58
  • I had the problem where the twig exception handler was intercepting it and returning the response. I think I solved it by creating a custom event listener with a higher priority and setting the response inside it. – mickadoo Nov 13 '16 at 15:52
  • Ths is the full configuration reference of JMS Bundle : http://jmsyst.com/libs/serializer/master/reference/yml_reference – Weenesta - Mathieu Dormeval Nov 18 '16 at 15:22

0 Answers0