Skip to content

Instantly share code, notes, and snippets.

@JohnMurray
Created January 14, 2018 10:12
Show Gist options
  • Save JohnMurray/f3da538d963f4051f63cc37d0ff858f8 to your computer and use it in GitHub Desktop.
Save JohnMurray/f3da538d963f4051f63cc37d0ff858f8 to your computer and use it in GitHub Desktop.
Mock networking API to produce errors
import scala.concurrent.Future
import scala.concurrent.ExecutionContext.Implicits.global
import scala.util.Random
object NetworkException extends Throwable
def networkRequest(): Future[String] = {
// let's assume a high rate of failure to make our examples
// more interesting
if ((Random.nextFloat * 100) < 80)
Future.failed(NetworkException)
else
Future.successful("<data>")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment