-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
#[MapRequestPayload]
does not handle invalid enums gracefully
#52705
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
Comments
Hello, I can try a PR during the #SymfonyHackday |
Instead of focusing on the Serializer, one could also catch and handle the Serializer's Maybe @Koc can chime in about that? |
During the SymfonyHackday, after discussing with @dunglas and @nicolas-grekas , we explored two initial approaches to address this without making significant changes to the Serializer but by working at the level of the
Upon delving deeper into the code, I then came across the concept of I don't know what to do after reading this pull request: #50201 |
Hi! I'd like to take over this issue! If we have to choose between the two solutions above, then I'd go for the second one. Throwing a custom exception (that inherits from However, I agree with @SebLevDev regarding the concept of @dunglas @nicolas-grekas : 5 months later, do you still think that catching the |
Sorry, is there any final solution to this issue? |
The current workaround I use:
|
Thanks! Cool solution:) |
up |
From my previous comment
I made some changes in my current usage:
The suffix Enum on the getter allows me to remove the @var string on the property |
I also encountered this problem, can you tell me if it will be solved by the framework? I really would not like to remake all the code that uses enum to the option proposed by @alexandre-le-borgne |
Symfony version(s) affected
6.3.8
Description
The
#[MapRequestPayload]
attribute handles invalid input (wrong type, missing fields) by returning a 422 Response and a message hinting at the problem(s). However when sending an invalid enum value, the result is a 500 Response.How to reproduce
Given the following setup
If you send a request containing the following Json
You get a 500 Response, even though a 422 would have been more sensible. The exception message is
Possible Solution
No response
Additional Context
The
BackedEnumNormalizer
handles failure differently depending on whether thehas_constructor
flag in the$context
is set:The
NotNormalizableValueException
case is handled in theRequestPayloadValueResolver
, theInvalidArgumentException
case is not.The text was updated successfully, but these errors were encountered: