tôi đã hạ cánh trên chủ đề này một số lần trên Trong vài ngày qua. Đối với bất kỳ ai khác trong trường hợp của tôi, nơi bạn đang sử dụng gói V2, bạn có thể tìm thấy tài nguyên sau đây khi nâng cấp FOSRestBundle hữu ích.
Nó bao gồm việc sử dụng bộ nối tiếp thay cho ngoại lệ ExceptionWrapperHandlerInterface.
https://github.com/FriendsOfSymfony/FOSRestBundle/blob/master/UPGRADING-2.0.md
- Tùy chọn exception_wrapper_handler cấu hình đã được gỡ bỏ. Sử dụng bình thường để thay thế.
Trước:
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'));
}
}
Sau (nếu bạn sử dụng serializer Symfony):
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;
}
}
bạn đã giải quyết này? Tôi gặp rắc rối tương tự –