In Play Framework 2.3, an action can produce a result from a successful future call like this:
def index = Action.async {
val futureInt = scala.concurrent.Future { intensiveComputation() }
futureInt.map(i => Ok("Got result: " + i))
}
But how can an action deal with a failed future call, i.e., a future that was completed by calling failure()
instead of success()
?
For instance, how could an action produce a InternalServerError
result with the message returned in the future's failure's throwable?
onComplete
and onFailure
callbacks don't seem to fit the action's flow (it needs to return a result, either from a successful future or a failed one).