Let’s say I want to return a BadRequest result type for all /foo URIs:
override def onBadRequest(r: RequestHeader, error: String) = {
BadRequest("Bad Request: " + error)
}
override def onRouteRequest(r: RequestHeader): Option[Handler] = {
if(r.uri.startsWith("/foo") onBadRequest("go away")
else super.onRouteRequest(r)
}
Of course does not work, since the expected return type is Option[play.api.mvc.Handler]
What’s the idiomatic way to deal with this, create a default Application controller method to handle filtered bad requests? Ideally, since I know in onRouteRequest that /foo is in fact a BadRequest, I’d like to call onBadRequest directly.
Should note that this is a contrived example, am actually verifying a URI yyyyMMdd date param, and BadRequest-ing if it does not parse to a JodaTime instance — basically a catch-all filter to sanitize a given date param rather than handling on every single controller method call, not to mention, avoiding cluttering up application log with useless stack traces re: invalid date parse conversions (have several MBs of these junk trace entries accruing daily due to users pointlessly manipulating the uri date in attempts to get at paid subscriber content)
As usual, the edge goes unanswered…
Came up with this to sanitize URI date params prior to passing off to Play router