Not verified
You can do something like this:
import scala.concurrent._ import play.api.libs.concurrent.Execution.Implicits._ def withRetry[T](retries:Int = 5)(f: => Future[T]) = f.recoverWith { case t:Throwable if (retries > 0) => withRetry(retries - 1)(f) }
And then in your own code, you can use it like this:
withRetry(retries = 2) { WS.url("some.url").get .map { response => require(someFunction(response) != "error", "Please retry") response } }
If you want to rewrite someFunction to Response => Boolean , you can use it like this:
def someFunction(r: Response): Boolean = ??? withRetry(retries = 2) { WS.url("some.url").get .filter(someFunction) }
source share