简体   繁体   English

如何对 akka-http 进行通用响应

[英]How to do a generic response for akka-http

I need to create a function that evaluates to a Route given a Future[Either[Error, T]] I do it like this我需要创建一个函数来评估给定Future[Either[Error, T]]的 Route 我这样做

def handleFuture[T] handleFuture(f: Future[Either[Error, T]]): Route = {
  onComplete(f) {
    case Failure(er) => complete(InternalServerError, err)
    case Success(Left(er)) => complete(BadRequest, er)
    case Success(Right(value)) => complete(OK, value)
  }
}

I have implicit marshallers/unmarshaller in scope for generic type A and I get a too many arguments for method complete error.我在泛型类型A范围内有隐式编组器/解组器,我得到了too many arguments for method complete错误的too many arguments for method complete

What am I doing wrong?我究竟做错了什么?

You have a typo.你有一个错字。 Change err to er :err更改为er

case Failure(er) => complete(InternalServerError, er)
                                               // ^

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM