Uncastable from request into validation error #857
Replies: 1 comment 1 reply
-
You could just throw your own ValidationException? CreationContext has the path to set for the message |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hi,
Is there any way to convert an uncastable into a validation error?
I am returning an
Uncastable::create()
from a custom cast for a property, which I am injecting in a request. I expected that invalid data (hence the uncastable) would result in a validation error but it just throws an exception (ieArgument given must be of type X, string given
.example code to illustrate:
controller:
dto:
cast:
post a request with the following body:
I understand validation is applied before casting (which makes sense), but I would like the data to be validated before attempting the cast. This would prevent the Uncastable, which just "returns the passed value" (the string "x" in the example) at the moment.
I could add (custom) validation rules, but I think it would be better if the rules are automatically applied. Any idea, or am I missing something obvious?
Thanks in advance
Beta Was this translation helpful? Give feedback.
All reactions