Playframework 如何从内部方法渲染和停止

Playframework 如何从内部方法渲染和停止,playframework,playframework-2.1,Playframework,Playframework 2.1,假设我有这个动作结构: def checkAccess(request: Request[AnyContent]) { if (shouldntGetAccess()) { // I want to return 404 and stop execution here } } def index = Action { implicit request => checkAccess(request) Ok } 如何决定从checkAcce

假设我有这个动作结构:

def checkAccess(request: Request[AnyContent]) {
    if (shouldntGetAccess()) {
        // I want to return 404 and stop execution here
    }
}

def index = Action { implicit request =>
    checkAccess(request)

    Ok
}
如何决定从
checkAccess()
返回404页并停止执行?这是在游戏1中通过简单调用
notFound()
实现的,但在游戏2中的行为似乎不一样


这可以通过让
checkAccess()
抛出一些异常,并添加一个过滤器来捕获它并呈现正确的响应来实现吗?如果您的代码提供了一个代码示例,那就太好了。

Hmm,有趣的函数方法。
def checkAccess(f: Request[AnyContent] => Result) = Action{ request => 
  if(shouldntGetAccess()){
  NotFound
}else{
  f(request)
}
}

def index = checkAccess{ request => 
  Ok("success")
}