Create Three Symfony Back Ends - Part #9 - Friendly error messages
Feb 14, 2023
In the previous video we wrote some edge case tests that cover what happens if we send in an empty title string, or try to say our hot new Album has -5 tracks. Far out, dude.
Whilst we are catching these gnarly situations, we aren't really helping our Symfony 4 JSON API consumers as we just say: "status is error, kthxbye!"
It would be much nicer if we said yes, this is an error and it's because X, Y, and Z.
Symfony's form has already done about 90% of the hard work for us. It knows what the errors are, and to which fields they apply.
But getting that information from Symfony's form component and converting it in to a nice bit of JSON is... not so easy.
Both FOSRESTBundle, and the Symfony API Platform will take care of this process for you. As we aren't using either of those at this point, we have to handle this problem ourselves.
Show More Show Less 