I just cannot figure out a way to google this. I have, for example, code like this:
import dispatch._
object Main extends App {
val svc = url("http://www.php.net/license")
val src:Promise[String] = Http(svc OK as.String) recover {
case StatusCode(301) => "got the 301, now where the heck should I go?"
case error => "caught error:" + error.toString
}
println(src())
}
From the dispatch package, recover takes a PartialFunction[Throwable,A] where A ends up being a String in my case. That url always returns 301, presumably with a message telling me where I should go instead. But in pattern matching on it, how do I access the plethora of methods that are inherited by statuscode that could give me an idea of what went wrong?
In haskell I’d do it like this:
case x of
sc@StatusCode(301) -> getMessage(sc)
error -> ...
If it is not possible to get the original object in scala, is there some way I could have written this code so that it would have worked?
I’m sorry I’m a complete idiot. I didn’t even think to try this even after writing my haskell solution: