I am using playframework 2.6.x for my Java application.
When I detected that the user request is invalid I would like to return 4XX with meaningful message.
In my Controller I could just
return badRequest("message");
But how do I do this somewhere deeper in the stack?
If I were using Scala the I could use Try or Either returns all the way to controller (even that is annoying depending on how deep in the stack we are talking about)
I was hoping that I can just
throw new BadRequest("message");
that DefaultHttpExceptionHandler
converts to HTTP 400 result; with appropriate message from the exception.
But I did not find such a thing.
I can be rolling my own exception handler and exception types. But was trying to avoid that if there is existing exception type that I can use.