2013-10-28 23 views
1

下面的控制器操作導致錯誤:斯卡拉播放Action.async不能化解好爲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])". 

每未來幾年內的行動應該OK(),所以我不明白爲什麼斯卡拉着決心期貨正確。

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

回答

0

我不知道在哪裏,但似乎有這個動作,這不是覆蓋我的情況下,結構的情況。 我重構了這個動作,它現在工作正常:

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