First set of third-party additions. #14

Closed
wants to merge 5 commits into
from

Projects

None yet

4 participants

@adamdecaf
Contributor

It seems that any third-party libraries that are part of Dispatch would be treated as a separate jar that could be downloaded. Given that, this is just a simple foursquare library to get the ball rolling.

Mostly I want to get people's thoughts on a good way to bring in support for popular api's, etc..

@adamdecaf
Contributor

There is a problem in that any HTTP status code that comes back which isn't 200 throws an exception. As seen by this line: https://github.com/dispatch/reboot/blob/master/core/src/main/scala/handlers.scala#L37

It would be nice to not throw that, but instead return that so we can deal with it. A lot of HTTP status codes don't mean failure.

@Burn0ut07

Thats only if you use the OkHandler (i.e. Http(url("http://www.google.com") OK as.String)) You could always use the > handler

@aappddeevv
Contributor

I know this is a 2 year old thread but I'll add the following to illustrate the last comment:

  /**
   * Accept the specified status code, throw an exception for any other status codes.
   * Use like `Http(req > acceptOnly(401, as.String))`.
   * For some reason the parser does not like `Http(req acceptOnly(401) as.String)``
   * so I had to code the class this way instead of an implicit class.
   */
  case class acceptOnly[T](code: Int, f: Response => T)
    extends dispatch.FunctionHandler(f) {

    override def onStatusReceived(status: HttpResponseStatus) = {
      if (status.getStatusCode == code)
        super.onStatusReceived(status)
      else throw StatusCode(status.getStatusCode)
    }
  }  
@n8han n8han closed this May 28, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment