繁体   English   中英

Scala Play Action.async无法将Ok解析为mvc.AnyContent

[英]Scala Play Action.async cant resolve 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])". 

操作中的每个Future都应该为Ok(),所以我不明白为什么Scala无法正确解析Future。

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])

我不知道在哪里,但似乎该诉讼中有一个案件未被我的案件结构涵盖。 我将动作重构为此,现在可以正常工作:

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")
  }
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM