Scala Play Action.async не может быть разрешен Ok as mvc.AnyContent
Следующее действие контроллера вызывает ошибку:
(block: => scala.concurrent.Future[play.api.mvc.SimpleResult])play.api.mvc.Action[play.api.mvc.AnyContent] cannot be applied to (scala.concurrent.Future[Object])".
Каждое будущее внутри действия должно быть в порядке (), поэтому я не понимаю, почему Scala не может правильно разрешить будущее.
def form = Action.async {
val checkSetup: Future[Response] = EsClient.execute(new IndexExistsQuery("fbl_indices"))
checkSetup map {
case result if result.status == 200 => Ok("form")
case result => {
val createIndexResult: Future[Response] = EsClient.execute(new FillableSetupQuery())
createIndexResult map {
indexCreated => Ok("form").flashing("success" -> "alles tutti")
} recover {
case e: Throwable => Ok("form error").flashing("message" -> "error indexerzeugung")
}
}
} recover {
case e: Throwable => Ok("form error").flashing("message" -> "error index query")
}
}
Завершить Errormsg:
overloaded method value async with alternatives: [A](bodyParser: play.api.mvc.BodyParser[A])(block: play.api.mvc.Request[A] => scala.concurrent.Future[play.api.mvc.SimpleResult])play.api.mvc.Action[A] <and> (block: play.api.mvc.Request[play.api.mvc.AnyContent] => scala.concurrent.Future[play.api.mvc.SimpleResult])play.api.mvc.Action[play.api.mvc.AnyContent] <and> (block: => scala.concurrent.Future[play.api.mvc.SimpleResult])play.api.mvc.Action[play.api.mvc.AnyContent] cannot be applied to (scala.concurrent.Future[Object])
1 ответ
Решение
Я не уверен, где, но кажется, что в этом действии был случай, который не был охвачен моей структурой дел. Я переделал действие на это, и теперь оно работает нормально:
def form = Action.async {
EsClient.execute(new IndexExistsQuery("fbl_indices")) flatMap {
index => if (index.status == 200) Future.successful(Ok("form"))
else {
EsClient.execute(new FillableSetupQuery()) map {
indexCreated => Ok("form").flashing("success" -> "alles tutti")
} recover {
case e: Throwable => Ok("form error").flashing("error" -> "error indexerzeugung")
}
}
} recover {
case e: Throwable => Ok("form error").flashing("error" -> "error index query")
}
}