title: Scala Future error handling with Either
body: <p>I am writing a wrapper for an API and I want to do error handling for applications problems. Each request returns a Future so in order to do this I see 2 options: using a <code>Future[Either]</code> or using exceptions to fail the future immediately. </p>
  
  <p>Here is a snippet with both situations, <code>response</code> is a future with the return of the HTTP request:</p>
  
  <pre><code>  def handleRequestEither: Future[Either[String, String]] = {
      response.map {
        case "good_string" =&gt; Right("Success")
        case _ =&gt; Left("Failed")
      }
    }
  
    def handleRequest: Future[String] = {
      response.map {
        case "good_string" =&gt; "Success"
        case _ =&gt; throw new Exception("Failed")
      }
    }
  </code></pre>
  
  <p>And here is the snippet to get the result in both cases:</p>
  
  <pre><code>handleRequestEither.onComplete {
    case Success(res) =&gt;
      res match {
        case Right(rightRes) =&gt; println(s"Success $res")
        case Left(leftRes) =&gt; println(s"Failure $res")
      }
    case Failure(ex) =&gt;
      println(s"Failure $ex")
  }
  
  handleRequest.onComplete {
    case Success(res) =&gt; println(s"Success $res")
    case Failure(ex) =&gt; println(s"Failure $ex")
  }
  </code></pre>
  
  <p>I don't like to use exceptions, but using <code>Future[Either]</code> makes it much more verbose to get the response afterwards, and if I want to map the result into another object it gets even more complicated. Is this the way to go, or are there better alternatives?</p>