使用简单的控制器尝试使用Play framework 2.5时出现的错误消息令人困惑。这就是我正在做的事情:
object UserController extends Controller {
def login = Action.async(BodyParsers.parse.json) { request =>
val body = request.body.validate[UserLogin]
// call the userService and validate the credentials
body.fold(
errors => {
BadRequest(Json.obj("status" -> "error", "message" -> JsError.toFlatJson(errors)))
}, // error here
message => {
Ok("")
} // error here
)
}
}
我收到错误消息:
"Expression of type Result does not conform to expected type _X"
答案 0 :(得分:1)
我需要将电话包裹在未来!所以这是如何做到的!
object UserController extends Controller {
def login = Action.async(BodyParsers.parse.json) { request =>
val body = request.body.validate[UserLogin]
// call the userService and validate the credentials
body.fold(
errors => {
Future.successful { BadRequest(Json.obj("status" -> "error", "message" -> JsError.toFlatJson(errors))) }
}, // error here
message => {
Future.successful { Ok("") }
} // error here
)
}
}