如何在play控制器中处理AskTimeoutException

时间:2015-10-16 18:09:56

标签: scala playframework akka future akka-remote-actor

您好我想包装AskTimeOutException并发送正确的消息....

  class Application @Inject()(system: ActorSystem) extends Controller {
  def index = Action { Ok("Welcome")}
  val ref: ActorSelection = system.actorSelection("akka.tcp://NLPSystem@127.0.0.1:5150/user/nlp")
  implicit val timeout = Timeout(5 seconds)
  def nlp(query: String) = Action.async {
      val fut: Future[NLPResponse] = (ref ? NLPRequest(query)).mapTo[NLPResponse]
      fut map {
        case e: akka.pattern.AskTimeoutException => InternalServerError("NLP engine is down please try after some time")
        case res: NLPResponse => Ok(res.response)
      }
  }
}

请建议我处理它的正确方法..

1 个答案:

答案 0 :(得分:2)

应使用recover combinator

处理未来错误
update