I have landed several times on this subject over the past few days. For anyone else in my situation when you are using a V2 package, you can find the following resource when updating the useful use of FOSRestBundle.
It covers the use of serializer instead of ExceptionWrapperHandlerInterface.
https://github.com/FriendsOfSymfony/FOSRestBundle/blob/master/UPGRADING-2.0.md
- Excluded configuration option exception_wrapper_handler. the use of normalizers.
Before:
config.yml
fos_rest: view: exception_wrapper_handler: AppBundle\ExceptionWrapperHandler
Handler
namespace AppBundle; class ExceptionWrapperHandler implements ExceptionWrapperHandlerInterface { public function wrap($data) { return new ExceptionWrapper(array('status_code' => 'foo')); } }
After (if you use the symfony serializer):
services.yml
services: app_bundle.exception_normalizer: class: AppBundle\Normalizer\ExceptionNormalizer tags: - { name: serializer.normalizer }
normalizer
namespace AppBundle\Normalizer; use Symfony\Component\Serializer\Normalizer\NormalizerInterface; class ExceptionNormalizer implements NormalizerInterface { public function normalize($object, $format = null, array $context = array()) { return array('status_code' => 'foo'); } public function supportsNormalization($data, $format = null) { return $data instanceof \My\Exception; } }
falconsmilie
source share