-
-
Notifications
You must be signed in to change notification settings - Fork 887
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
Invalid (or unclear to me) handling of data returned from MessageHandler::__invoke() #2550
Comments
Hi! When using |
Hi @soyuka, I'm trying to follow what is documented in https://api-platform.com/docs/core/messenger/
Could you please clarify - how I should configure/code to be able to return Message bus is in sync mode. |
Did you check out the symfony documentation to see how stamps work: https://symfony.com/doc/current/components/messenger.html ? |
Hi @soyuka Debugging shows that envelope with result object (that was returned from handler's __invoke()) are being stamped with HandledStamp. I'm using sync handler, HandledStamp is set automatically, I tried to set
|
You can't return a response directly from the Handler, best is to return an object that will replace the original one. Another solution would be to return your updated resource, and if you need a different representation of your data to create an |
Hi @soyuka , {
"passwordResetToken": "xyz",
"plainPassword": "abc"
} In handler, I'm verifying if I had it implemented before with DTO and Event Listener, but it was more code and not so beautiful like with message handler. Adding of additional middlware into the message bus just for this case - seems to be an overcomlication. If I explicitly set that output class should be for example |
The alternative would be to have an event listener before the WriteListener or a data persister but then you'll have issues with the token.
Can't you return the token object instead of a Response? |
Well, I already have a working solution with Event listener, but I'm trying to rewrite it in much more clear way using Messenger:
// creating a new JWT token
$response = $this->authenticationHandler->handleAuthenticationSuccess($user);
$content = $response->getContent();
return $content; |
I need to try this, would you happen to have a repository with this example? |
Unfortunately, it's in private repo. |
Would be amazing if you could! |
hey @soyuka to test the functionality I'm talking about - check
|
hey @soyuka |
I haven't forget just couldn't find the time yet. Note that I've discussed this with other's and it really looks like messenger shouldn't be used in this case the event listener is fine. Although, I still want to check if we can use a Response directly from the messenger as you tried, I'll keep you updated asap. |
Thank you @soyuka ! |
Still didn't had time but in the meantime maybe that this could be of interest: #2495 (comment) |
Hi @soyuka, The problem still the same - when I return Response (or any subclass of it) from handler's __invoke() it ends up with exception.
And it doesn't matter what I will put in But see how beautiful it could be: More or less the same thing implemented with Events - if event handler returns response - processing stops and it will be sent to user. |
fixed with #2628 really sorry about the long delay :) |
|
Ok, I will try this new feature and reply back here with the notes ) |
Got this working on v2.4:
|
Closing this as it's tested, lmk if you still have issues. |
ok @soyuka |
Answer: #2638 :p Although I think that the Ramsey identifiers work on 2.4 |
Hello,
it seems handling of data returned from
__invoke()
method of class that implementsMessageHandlerInterface
is not correct.Sending request to
/users/password-reset-confirmation
.Expected behavior:
Api platform should return a response object that was returned from
__invoke()
.In this particular case I'm trying to return
JWTAuthenticationSuccessResponse
which extendsJsonResponse
.Current behavior:
DTO class
UserPasswordResetConfirmation.php
:API Resource config
user_password_reset_confirmation.yaml
:Message handler class
UserPasswordResetConfirmationHandler.php
:Debugging showed that event is populated with response object
vendor/api-platform/core/src/EventListener/WriteListener.php
at lines 60-66:but later on somewhere controller result is overwritten with DTO object
UserPasswordResetConfirmation
, than becomes a cause of an exception.The text was updated successfully, but these errors were encountered: