I get my response from my requests this (simple, blocking) way:
val response = Http(req)()
But I got this error from Play! framework:
ExecutionException: java.net.ConnectException: Connection refused to http://localhost:8983/update/json?commit=true&wt=json
I have never thought about exception handling in Dispatch or Scala for that matter. What are the errors i must watch for in Dispatch library? What is the statement to catch each type/ class of errors?
One common way of handling exceptions in this kind of situation, where failure of some kind isn’t actually that exceptional, is to use
Either[Throwable, Whatever]to represent the result. Dispatch 0.9 makes this convenient with theeithermethod onPromise(which I use in my answer to your earlier question, by the way):Now you can very naturally use pattern matching to handle exceptions:
There are also many other ways that you can use
Eitherto make handling failures more convenient—see for example this Stack Overflow answer.