I am having an issue in my Play action where my view page requires a ApiResponse object but I am a Future[ApiResponse] and can't seem to "unwrap" the future.
def confirm(token: String) = Action async { request =>
// loadTokenInfo returns Future[Option[SP]]
loadTokenInfo(token).map { maybeSP =>
maybeSP match {
case Some(sp) =>
val someConfig = SomeConfiguration(..)
// confirmSubscription returns Future[ApiResponse]
for {
apiResp <- apiService.confirmSubscription(sp.account, sp.website, sp.list, sp.listMember)
} yield Ok(views.html.subscription.confirm(ConfirmPageViewModel(someConfig, sp, apiResp)))
case _ =>
Ok(views.html.errorpage.empty(PageNotFound("asdf")))
}
}
}
I am getting the error:
[error] found : scala.concurrent.Future[play.api.mvc.Result] [error] required: play.api.mvc.Result
I tried to map over the apiResp also but that didn't work:
apiResp.map { r =>
Ok(views.html.subscription.confirm(ConfirmPageViewModel(pageConfig, sp, r)))
}
Do I have to call Await.result here? I don't want to block obviously but not sure what to do at this point.