I have a code sample as below where I am using WSClient to make API calls. I am using 2.5.x and Scala 2.11.11 (using WSClient provided by Play not stand-alone). In an exception condition I need to return WSResponse object to the caller of this method. From documentation I found Ahc package which provides AhcWSResponse. Any idea how can I create the WSResponse object ? I tried based on a link as below but that does not work.
How to create a WSResponse object from string for Play WSClient
def fetchData (request: WSRequest): Future[WSResponse] = {
request.withQueryString("apitoken" -> token).get().flatMap { dataResponse =>
if (dataResponse.status == 200) {
Future(Ok(dataResponse.json))
} else if (dataResponse.status == 400) {
...
}
}.recover {
case e: Exception =>
//need to return a WSResponse object - how do i create one here
}
}