I have a controller like this
def index = Action.async { implicit request =>
implicit val lang = Lang(Language.mapping.lift(request.queryString("country").head).getOrElse("en"))
///...
futureResult.map{...}
.recover {
case error =>
displayError(error)
}
}
private def displayError(throwable: Throwable)(implicit lang: Lang) = {
throwable match {
case error: NotFoundException => Status(404)(views.html.errors.notFound("resource.notfound"))
//...
}
}
And an error template :
@(message: String)(implicit lang: Lang)
<!DOCTYPE html>
<p>@Html(Messages(message))</p>
...
I've noticed a few things :
- If
val lang = ...
is not defined as implicit, compile is still working, I can calldisplayError
method - If you don't pass lang explicitly to the displayError like this :
displayError(error)(lang)
, the value passed to the private method is not the one defined by my code, but the last one used by my browser (I guess in a cookie?)
So looking at the code it seems to be a simple private method call, but is Play doing some implicit values modifications before each method call, even private ones, even without passing through the router ?
Thanks