I'm getting the following compilation error in the future recover
line:
type mismatch; found : scala.concurrent.Future[Any] required: scala.concurrent.Future[play.api.mvc.Result]
I'm returning Ok()
which is a Result
object, so why is the compiler complaining?
class Test2 extends Controller {
def test2 = Action.async { request =>
val future = Future { 2 }
println(1)
future.map { result => {
println(2)
Ok("Finished OK")
}
}
future.recover { case _ => { // <-- this line throws an error
println(3)
Ok("Failed")
}
}
}
}
2
orOk("Failed")
. This is not Java, you can't doreturn thisStuff else .. return that...
. The last object you are returning from your method is the result... See answer below. – insan-e