I have an API which takes multiple input values. One of them is a date. When the date is sent, all is fine. But, when the user isn't sending a date, I have an error 500 with this error message:
Invalid datetime "Some invalid data", expected format Y-m-d\TH:i:sP.
So I wanted to check if the data sent had the format required.
But I don't understand how things are working, hope you can help.
This is what I have
/**
 *
 * @Rest\Post(
 *     path = "/signup",
 *     name = "api_users_add"
 * )
 * @Rest\View(StatusCode=201, serializerGroups={"user_detail"})
 * @ParamConverter(
 *     "user",
 *     converter="fos_rest.request_body",
 *     options={"deserializationContent"={"groups"={"Deserialize"}}},
 * )
 * @ParamConverter(
 *     "profile",
 *     converter="fos_rest.request_body",
 *     options={"deserializationContent"={"groups"={"Deserialize"}}},
 * )
 */
public function postUserAction(Request $request, User $user, Profile $profile)
{
    if (!preg_match("^[0-9]{4}-[0-1][0-9]-[0-3][0-9]$",$profile->getBirth())){
        return new JsonResponse([
            'success' => false,
            'message' => "Date d'anniversaire au mauvais format"
        ]);
    }
}
But in fact, I never go into this condition, the error 500 is triggered before.
I guess this has something to do with the @ParamConverter from Profile who can't "deserialize" when birth is not a DateTime.
Thing is, I would like to check what is sent (as I did into my condition) in order to avoid this internal error. But I can't find where this is handled on my code.
Thanks for the help.
Considering this : symfony doc for Param converter fos rest bundle
What I am looking for is to find where the validationErrors are specified.
 
    