savonrb / wasabi

A simple WSDL parser
MIT License
90 stars 84 forks source link

Resolver raises exception with raw "#<HTTPI::Response>" string as its message #21

Closed wapcaplet closed 11 years ago

wapcaplet commented 11 years ago

I've run into a case when attempting to fetch a WSDL, and the server returns a 404 error. When wasabi handles this in resolver.rb, it raises an exception with the response object as the exception message:

    def load_from_remote
      request.url = document
      response = HTTPI.get(request)

      raise HTTPError, response if response.error?  # <----
      response.body
    end

This get converted to a plain "#<HTTPI::Response:0x0000...>" string once it's passed into the HTTPError constructor, instead of a more meaningful exception message like "Error 404". Inspecting the HTTP::Response object itself, I don't see much that would be useful (since body may be an arbitrarily large blob of HTML), so I wonder if maybe at least including the response code would result in a saner-looking exception, i.e.:

    raise HTTPError, "Error: #{response.code}" if response.error?

Even better, enhance the HTTPError exception class to wrap the faulty HTTPI::Response instance itself, rather than just its hex-addressed string representation.

rubiii commented 11 years ago

@wapcaplet sounds like a reasonable change. would you be able to address this?

wapcaplet commented 11 years ago

@rubiii Sure, I'll take a crack at it when I have a chance.

rubiii commented 11 years ago

this has been released with v3.1.0.