Open GleisonOliveira opened 1 year ago
Hi everyone.
I'm facing a problem with the last version of lib, we are upgrading to symfony 6.2 and version 3.5 of this lib, but the exceptions serializer are not been called anymore.
6.2
3.5
My config is
fos_rest: allowed_methods_listener: true service: serializer: primepass.fos_serializer format_listener: rules: - { path: '^/resque', priorities: ['text/html', '*/*'], fallback_format: html } - { path: ^/, prefer_extension: true, fallback_format: json, priorities: [ json ], } exception: enabled: true map_exception_codes: true codes: 'Primepass\ApiBundle\Exception\ValidateException': 400 'Primepass\ApiBundle\Exception\NotFoundException': 404 'Primepass\ApiBundle\Exception\InterNotFoundRequestException': 404 messages: 'Primepass\ApiBundle\Exception\NotFoundException': true 'Primepass\ApiBundle\Exception\ValidateException': true
My serailizer is
<?php namespace Primepass\ApiBundle\Serializer; use Doctrine\ORM\EntityManagerInterface; use FOS\RestBundle\Serializer\SymfonySerializerAdapter; use Primepass\ApiBundle\Connection\ProviderIntegration\ProviderIntegrationConnection; use Primepass\ApiBundle\Serializer\FactoryInterface; use Primepass\ApiBundle\Serializer\Normalizer; use Symfony\Component\Serializer\Encoder\JsonEncoder; use Symfony\Component\Serializer\Serializer; class FosSerializerAdapterFactory implements FactoryInterface { /** * @var EntityManagerInterface */ private static $em; /** * @var ProviderIntegrationConnection */ private static $providerIntegrationConnection; /** * @param EntityManagerInterface $em * @param ProviderIntegrationConnection $providerIntegrationConnection * @return SymfonySerializerAdapter */ public static function create(EntityManagerInterface $em, ProviderIntegrationConnection $providerIntegrationConnection): SymfonySerializerAdapter { self::$em = $em; self::$providerIntegrationConnection = $providerIntegrationConnection; $serializer = new Serializer( self::getNormalizers(), self::getEncoders() ); return new SymfonySerializerAdapter($serializer); } /** * @return array */ private static function getNormalizers() { return [ new Normalizer\ExceptionNormalize, ]; } /** * @return array */ private static function getEncoders() { return [new JsonEncoder]; } }
and my normalizer is
<?php namespace Primepass\ApiBundle\Serializer\Normalizer; use Primepass\ApiBundle\Exception\AccessDeniedException; use Primepass\ApiBundle\Exception\NotFoundException; use Primepass\ApiBundle\Exception\ValidateException; use Primepass\ApiBundle\Exception\InvalidRequestException; use Primepass\ApiBundle\Exception\RateLimitException; use Symfony\Component\Serializer\Normalizer\NormalizerInterface; use Symfony\Component\Serializer\SerializerAwareInterface; use Symfony\Component\Serializer\SerializerAwareTrait; use Symfony\Component\ErrorHandler\Error\FatalError; class ExceptionNormalize implements NormalizerInterface, SerializerAwareInterface { use SerializerAwareTrait; /** * @param object $object * @param string $format * @param array $context * * @return array */ public function normalize($object, $format = null, array $context = array()): array { return [ 'error' => [ 'code' => $object->getExceptionError(), 'message' => $object->getExceptionMessage(), 'details' => $object->getValidateErrors() ] ]; } /** * * @param mixed $data * @param string $format * * @return boolean */ public function supportsNormalization($data, $format = null) { return ( $data instanceof ValidateException || $data instanceof NotFoundException || $data instanceof InvalidRequestException || $data instanceof AccessDeniedException || $data instanceof FatalError || $data instanceof RateLimitException ); } }
and my serializer service are registered
primepass.fos_serializer: class: 'FOS\RestBundle\Serializer\SymfonySerializerAdapter' factory: [Primepass\ApiBundle\Serializer\FosSerializerAdapterFactory, create]
This code was working well in version 2.4.
2.4
There is any suggestion to how to solve this?
Hi everyone.
I'm facing a problem with the last version of lib, we are upgrading to symfony
6.2
and version3.5
of this lib, but the exceptions serializer are not been called anymore.My config is
My serailizer is
and my normalizer is
and my serializer service are registered
This code was working well in version
2.4
.There is any suggestion to how to solve this?