Created
January 14, 2018 10:12
-
-
Save JohnMurray/f3da538d963f4051f63cc37d0ff858f8 to your computer and use it in GitHub Desktop.
Mock networking API to produce errors
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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