【发布时间】:2014-03-27 17:56:59
【问题描述】:
我想对异常处理机制提出一些建议。我目前终于有了传统的 try catch,但我知道它在风格上不起作用。那么处理异常的最佳功能方式是什么。我尝试查看 Scala 手臂,但我想它最终只是 try catch 的功能包装器!建议?这是我的 Play 控制器,我想在其中处理抛出的异常并将纯字符串发送回客户端!
def testmethod = Action(parse.maxLength(10 * 1024 * 1024, parser = parse.anyContent)) { implicit request =>
request.body match {
case Left(_) => EntityTooLarge
case Right(body) => {
println(request.headers.toSimpleMap)
val js = // Get the value from the request!!!
val resultJsonfut = scala.concurrent.Future { longRunningProcess(js) }
Async {
if(request.headers.toSimpleMap.exists(_ == (ACCEPT_ENCODING, "gzip"))) {
resultJsonfut.map(s => {
val bytePayload = getBytePayload(s) // How to handle exceptions thrown by getBytePayLoad????
Ok(bytePayload)
})
} else {
resultJsonfut.map(s => Ok(s))
}
}
}
}
}
【问题讨论】:
标签: scala playframework