I'm writing a web application in Spray and am using the case class validation method described at the bottom of this article:
http://spray.io/documentation/1.2.3/spray-routing/advanced-topics/case-class-extraction/
It works great, but I'm unhappy with the message returned to the client. Aside from the fact that it's ugly, it exposes some details about the back end:
The request content was malformed: Instantiation of [simple type, class com.mycompany.models.users.User$Login] value failed: requirement failed: Invalid email address (through reference chain: com.mycompany.models.users.Login["password"])
I'd like it to say, simply
Invalid email address
Any idea on how to accomplish this?
Update
I've implemented what @soong suggested, but it's good not great (so far).
My require code is require(!zipcode.isEmpty, "Invalid zipcode")
My rejection handler code:
implicit def validationRejectionHandler = RejectionHandler {
case MalformedRequestContentRejection(msg, cause) :: _ =>
complete(BadRequest, s"$msg")
}
The problem is that the message I want ("Invalid zipcode") is wrapped in some other text:
cause.detailMessage = "requirement failed: Invalid zipcode"
Any way to get my exact error message without having to do string manipulation?