3

我有这个:

class RichResponse(future: Future[WSResponse]) {

  def failIfNot(statuses: Int*)(implicit executor: ExecutionContext) = {
    future.map { response =>
      if(statuses.contains(response.status)) {
        response
      } else {
        throw new RuntimeException("Bad HTTP response for %s: %s".format(
          response.ahcResponse.getUri, response.status))
      }
    }
  }

}

object Implicits {

  implicit def responseToRichResponse(future: Future[WSResponse]) = new RichResponse(future)

}

用法是这样的:

WS.url("http://stackoverflow.com/questions/ask").failIfNot(OK)

但是从2.1升级到2.3后,achResponse就不再存在了。如何获得底层(更完整的)响应对象?

4

1 回答 1

1

我开始阅读源代码,看来

response.underlying[NingWSResponse].ahcResponse

将是做到这一点的新方法。

似乎不是很安全....

于 2014-08-07T08:06:18.223 回答