Currently my API endpoint works fine in the happy path if the JSON value corresponds to my case class correctly.
How can I return a user friendly message when it doesn't?
case class UpdateUserRequest (
registrationStatus: String,
level: Int
)
For example, say the value level has to be between 10 and 20. And the String value for registraition status has to be either "a", "b" or "c".
case updateUser @ PUT -> Root / "users" as user => {
for {
updateReq <- updateUser.req.as[UpdateUserRequest]
....
apiResponse <- Ok(200, true, "")
} yield apiResponse
}
My response object is like:
case class ApiResponse(
statusCode: Int,
success: boolean,
errorMessage: String
)