You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
why you cannot use simple conditional statement for null check and throw ex?
exception usually indicates a developer error at the code. here you have user error case so we don't have to throw an exception
why you cannot use simple conditional statement for null check and throw ex?
Because it is an optional parameter. Consider a classic example of a book store API where I'd have a method to list books /GET /books?[authorId={uuid}]. Since authorId is optional I will return all the books if it is null (missing). However, if user of the API asks for GET /books?authorId=620a8db4-8890-4c14-b1f5-4ed2fac35e2c I will return only books by this author. But if the user makes mistake and asks for GET /books?authorId=Tolkien I do not want to return all the books as if the authorId was legitimately null. I want to return an error to the user you must use id.
This works with Micronaut's top level @QueryValue parameters, but does not work for @Format("deep-object") @QueryValue.
This might also be the case for other @Format annotations - I have not checked. (The others are csv, ssv, pipes and multi). I am pretty sure multi works, but csv does not, but this bug is only about the deep-object format, as the current behavior makes the least sense there.
Expected Behavior
When the user supplied value can not be converted to the desired type (e.g. UUID) an exception should be thrown.
Actual Behaviour
If the input invalid, the value is set to
null
(or default value for the type) as if there was no input at all.Steps To Reproduce
I'd prefer a conversion error.
Note that the
ConversionErrorException
is thrown if the parameter wastest(@QueryValue("id") UUID id)
and user supplied an invalid value there.Environment Information
Example Application
No response
Version
4.6.3
The text was updated successfully, but these errors were encountered: