I have a JSON REST API server built with Play framework v2.3 with scala, and I have controller's action like this for example:
def register = Action.async(BodyParsers.parse.json) { implicit request =>
request.body.validate[Register].fold(
errors => Future.successful(BadRequest(JsError.toFlatJson(errors))),
register => {
// do something here if no error...
}
)
}
For simplicity, I handle the validation error with JsError.toFlatJson
(note: JsError.toFlatJson
is deprecated in newer Play, the replacement is JsError.toJson
).
The problem is the json result have cryptic message like:
{"obj.person.email":[{"msg":"error.email","args":[]}]}
Above json indicates the person's email is invalid.
Is there a way to convert the error json result into more readable message?
I don't want the client apps should doing the mapping/conversion of the obj.person.email
or error.email
. I prefer the server does it before returning the json to the client apps.