将隐式参数传递给 Future.recover

Passing an implicit parameter to Future.recover

我想将隐式参数传递给我用于 recover 我的 Future 的部分函数。

def delete(id: Long) = ... { implicit something =>
  serviceLayer.doSomething(id).recover(errorHandler)
}

def errorHandler: PartialFunction[Throwable, Result] = {
    // I want to access the implicit parameter here
    case e@SomeException(message) => ... and here
    case _ => ... and here
}

然后您的 errorHandler 需要接收 something 作为 implicit parameter:

def delete(id: Long) = ... { implicit something =>
  serviceLayer.doSomething(id).recover(errorHandler)
}

def errorHandler(implicit something: Something): PartialFunction[Throwable, Result] = {
    // Access something here
    case e@SomeException(message) => ... and here
    case _ => ... and here
}