Pergunta

I'm using Play framework 2.1.1 and as I tried to add a Global object to handle certain cases like BadRequest, HandlerNotFound and so on, I'm facing a strange error:

Here is how my Global.scala looks like:

object Global extends GlobalSettings {

  override def onStart(app: Application) {
    Logger.info("Application has started")
  }

  override def onStop(app: Application) {
    Logger.info("Application shutdown...")
  }

  override def onHandlerNotFound(request: RequestHeader): Result = {
    NotFound(
      views.html.common.notFoundPage(request.path)
    )
  }
}

Here is what I see when I start my application:

overriding method onHandlerNotFound in trait GlobalSettings of type (request: play.api.mvc.RequestHeader)scala.concurrent.Future[play.api.mvc.SimpleResult]; method onHandlerNotFound has incompatible type 

It actually fails on compilation and spits out the error above. What is the reason behind this? I'm confused ad my IntelliJ does not show any errors!

Foi útil?

Solução

Are you sure you are using Play Framework 2.1 when building your project?

The 2.1 branch indeed defines in GlobalSettings:

def onHandlerNotFound(request: RequestHeader): Result

While the 2.2 branch reads:

def onHandlerNotFound(request: RequestHeader): Future[SimpleResult]

Maybe you have different versions configured in IntelliJ and your build scripts?

For the 2.2 version you could write:

override def onHandlerNotFound(request: RequestHeader): Future[SimpleResult] = {
  Future.successful(NotFound(
    views.html.common.notFoundPage(request.path)
  ))
}
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top