I have following code in my play 2 app:
Controller:
...
def getUserById(id: Long) = Action.async {
try {
userService.findById(id)
.map(u => Ok(Json.toJson(u))
.recover {
case e: Exception => Ok("Exception got")
}
}
}
...
Service:
...
override def findAll: Future[Seq[User]] = {
throw new Exception("Error 1")
}
...
But in controller I cannot catch exception thrown in the service (recover block somehow ignored). Instead, play standard error page with Exception "Error 1" is displayed.
What am I doing wrong?
Future.failed(new Exception("Error 1"))
– dk14