Reputation: 1105
I would like to somehow catch the 'Execution exception' which is normally shown in browser. I just don't like the fact that I have to validate data manually, when they seem to be validated by Play anyway.
For example I would like to catch exceptions like the one below.
[IllegalStateException: Error(s) binding form: {"email":["Valid email required"]}]
It appears after User user = Form.form(User.class).bindFromRequest().get();
in my example.
Upvotes: 1
Views: 794
Reputation: 4463
IllegalStateException
is a runtime exception and is not meant to be caught.
Replace your code with:
Form<User> userForm = Form.form(User.class).bindFromRequest();
if(userForm.hasErrors()) {
return badRequest();
} else {
User user = userForm.get();
// whatever
return ok();
}
Upvotes: 1