Dealing with HTTP response codes in dispatch-json calls

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Dealing with HTTP response codes in dispatch-json calls

Gregg
I have a call like this:

new Http()(paramCall ># {
        js => js.asInstanceOf[JObject].values
      })

I need to deal with Http codes other than 200 (eg 400), get the error message from the response and do stuff with it.

What's the idiomatic way to accomplish this, effectively a try/catch only with Http?

Thanks for any ideas.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Dealing with HTTP response codes in dispatch-json calls

n8han
Administrator
It depends on whether the non 20x response can be processed by the provided Handler. If it can you (if in this case it is a json object) you can easily expand the range of acceptable response codes with the `when` method:

http://sourced.implicit.ly/net.databinder/dispatch-core/0.8.0/executor.scala.html#18247

Otherwise, you can catch the exception or use the "allow any status code with x" flow defined in HttpSpec:

http://sourced.implicit.ly/net.databinder/dispatch-http.test/0.8.0/HttpSpec.scala.html

That one allows you to pattern match on the status code and call the response handler against the response if it is expected to work for the status value.

Nathan
Loading...