I’ve started working on Play almost a week ago, what I’m trying to do right now is to intercept type validation done by routes file.
I’m doing fully server programming, no forms are involved all the data I get is through uri.Now consider following Rout
GET /send/request/*to/*from controllers.Req_controller.sendRequest(to: Int, from:Int)
if I’ll enter a non numeric character or a string instead of an integer, It’ll give me type violation error.
I don’t want play to do this, i want to handle these errors myself, returning a JSon object is a good option.
But I don’t want,
Bad request For request 'GET /send/request/3/f' [Cannot parse parameter from as Int: For input string: "f"]
Help will be highly appreciated
Params in
routeswith asterisk are forStringspanning several ‘slash-segments’ and should be placed somwhere at the end ofroutesfile, ie:will match:
In your case you should use ‘colon version’ of the param:
edit
To make basic interception you can just override
onBadRequest()method with Global object (bottom).You can also send whole
*pathas aa/b/cstring to your controller (like in very first sample route in this answer) and then split it and validate part by part in some more sophisticated scenario, anyway as can you see there are ome possibilities and I’m sure that you’ll choose something.