Scala 玩得开心!2.2错误处理
希望有人能帮我。我现在正在尝试编写一个隐式def,它可以获取特定的java.net.ConnectException并返回ServiceUnavailable,而不是InternalServerError。以下是与许多其他错误非常相似的现有控制器方法:Scala 玩得开心!2.2错误处理,scala,playframework,playframework-2.2,implicit-conversion,implicit,Scala,Playframework,Playframework 2.2,Implicit Conversion,Implicit,希望有人能帮我。我现在正在尝试编写一个隐式def,它可以获取特定的java.net.ConnectException并返回ServiceUnavailable,而不是InternalServerError。以下是与许多其他错误非常相似的现有控制器方法: def list = SecuredAction { implicit request => resource.Messaging.forClient(clientId.get).eitherRaw match {
def list = SecuredAction { implicit request =>
resource.Messaging.forClient(clientId.get).eitherRaw match {
case Right(o) =>
Ok( o )
case Left(e) =>
logger.error("Error occured attempting to update message.")
logger.error(ErrorWriter.writeString(e))
InternalServerError
}
}
现在,我无法在上面的e上获取隐式def。不知道从哪里开始。下面是一些关于我要写的东西的伪代码:
implicit def handleConnectException(e: java.net.ConnectionException) = {
logger.error(ErrorWriter.writeStackTrace(e))
ServiceUnavailable
}
我知道ConnectException包含一条消息,所以它是否需要是ConnectException[String]
非常感谢你的帮助 InternalServerError是一个可接受的返回值,因此编译器永远不会寻找隐式转换。您必须用HandleConnectionExceptionOne显式替换InternalServerError。