ford prefect
ford prefect

Reputation: 7378

TypeError Expected: Result, Actual: Future[SimpleResult]

I am working on a Scala service in Play to act as a proxy for another service. The problem I am having is that IntelliJ is giving me a type error saying that I should be returning a Future[SimpleResult] instead of a Result Object. Here is what I have:

def getProxy(proxyUrl: String) = Action { request =>
  val urlSplit = proxyUrl.split('/')
  urlSplit(0) 
  WS.url(Play.current.configuration.getString("Services.url.um") + proxyUrl).get().map { response =>
    val contentType = response.header("Content-Type").getOrElse("text/json")
    Ok(response.body)
  }
}

How do I fix this so I can return a Result object?

Upvotes: 1

Views: 491

Answers (1)

Michael Zajac
Michael Zajac

Reputation: 55569

Since Play WS.get() returns a Future[Response], which you're mapping to Future[Result], you need to use Action.async instead of Action.apply:

def getProxy(proxyUrl: String) = Action.async { request =>
    val urlSplit = proxyUrl.split('/')
    urlSplit(0) 
    WS.url(Play.current.configuration.getString("Services.url.um") + proxyUrl).get().map { response =>
        val contentType = response.header("Content-Type").getOrElse("text/json")
        Ok(response.body)
    }
}

Upvotes: 4

Related Questions