ErrorHandler #12938
Unanswered
KliptekMahesh
asked this question in
Q&A
ErrorHandler
#12938
Replies: 1 comment
-
I don't have the time to give you a fully fledged answer, but just as a hint: You could use the Play forms feature for your JSON API endpoints and then use the form validation feature to validate the incoming JSON (The pseudo code if (form.hasErrors()) {
return badRequest(form.errorsAsJson());
} |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hi I am new to playframework. I have a question.
In case the json string (provided as input to my http endpoint) can’t be parsed (eg is missing fields relative to the desired class, fields are of the wrong type, etc), Play automatically generates a 400 Bad Request. However, if the construction of my class (that I’m serializing the JSON input into) has some requirements that are checked via require() statements, when those requirements are not met Play is generating a server error… which is unexpected because, logically, some input requirement is not being met so my application should generate a 400 Bad Request. require() will throw an IllegalArgumentException if not satisfied. Should Play be checking for these exceptions alongside the JSON parsing ones it currently uses to make the determination to return a 400 Bad Request?
Thanks.
Beta Was this translation helpful? Give feedback.
All reactions