Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Subscribing Handler not used (FOSRestBundle: ExceptionHandler) #626

Closed
juliusstoerrle opened this issue Dec 4, 2017 · 11 comments
Closed

Comments

@juliusstoerrle
Copy link

Hey,
since upgrading I do get the "Resources not allowed in seralized data" error. This happens to me when serializing an exception via the ExceptionController in the FOSRestBundle. The Bundle registers a Handler for the \Exception Class which formats the exception and throws out all the resources...

The Handler registers as:
[ 'direction' => GraphNavigator::DIRECTION_SERIALIZATION, 'format' => 'json', 'type' => \Exception::class, 'method' => 'serializeToJson', ]

ExceptionHandler::getSubscribingMethods() is actually being called and the handler gets registered but not called during serialization.
I actually also had problems with my very own handlers when setting the type in the handler to \SomeObject::class. Somehow it did not use the Handler then so I'm using strings there and configure the properties with Annotations, but that not possible here.

@goetas
Copy link
Collaborator

goetas commented Dec 4, 2017

Are you using a "custom" exception ? (that maybe has a property of type resource) ?

@kbkk
Copy link

kbkk commented Dec 8, 2017

I guess my issue is partially related to this. With sf4 and jms bundle ^2.3 I get the serialization error with Doctrine exceptions (which didn't happen before).
Simple test case:

        $serializer = \JMS\Serializer\SerializerBuilder::create()->build();
        $ex = new \Doctrine\DBAL\Exception\UniqueConstraintViolationException(
            '',
            new \Doctrine\DBAL\Driver\Mysqli\MysqliException('', null)
        );
        $serializer->serialize($ex, 'json');

@goetas goetas closed this as completed Dec 8, 2017
@goetas
Copy link
Collaborator

goetas commented Dec 8, 2017

if the exception contains a resource, you have to take care of serializing (or excluding) it

@kbkk
Copy link

kbkk commented Dec 8, 2017

My point is the test case above works in a sf3.3 project with jms bundle 2.2 without any additional configuration. Would you care to explain how to get this working with jms 2.3?

@goetas
Copy link
Collaborator

goetas commented Dec 9, 2017 via email

@kbkk
Copy link

kbkk commented Dec 9, 2017

I am sorry for the trouble, the test case is wrong. I think it is an issue with FOS Rest Bundle. Seems like in the working project it falls back to Symfony Serializer but not in the new one. I should start an issue on FOS Rest Bundle.

@juliusstoerrle
Copy link
Author

juliusstoerrle commented Dec 9, 2017

Hey, I had started an Issue over there already about this topic (FriendsOfSymfony/FOSRestBundle#1790 (comment)) . The reason why I opened this Issue here is because the Handler from the Rest Bundle seems to be registered correctly.

@juliusstoerrle
Copy link
Author

@goetas Sorry for not responding to:

Are you using a "custom" exception ? (that maybe has a property of type resource) ?

Yes the exception has a property of that type (its not a custom exception, but one from the sf framework), but the Serialization Handler is supposed to remove that.

@goetas
Copy link
Collaborator

goetas commented Dec 9, 2017

"Serialization Handler" ? which one?

@juliusstoerrle
Copy link
Author

https://github.com/FriendsOfSymfony/FOSRestBundle/blob/master/Serializer/Normalizer/ExceptionHandler.php

@juliusstoerrle
Copy link
Author

Well my bad, when changing from SF4 Rcs to the 4.0 release I also changed the fos/rest version which resulted in not pulling some changes from an open pull request @xabbuh made. I changed that back and now it seems to work fine (hope it stays like that).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants