Get ahcResponse from Play WS

I had this:

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)

}

      

The usage was like this:

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

      


But after upgrading from 2.1 to 2.3, it is achResponse

no longer present. How can I get the basic (and more complete) response object?

+3


source to share


1 answer


I started reading the source and it seems that

response.underlying[NingWSResponse].ahcResponse

      



is a new way to do it.

Doesn't seem very typical ...

+1


source







All Articles