#3 √ resolved
John Nunemaker

Expose response codes in some way

Reported by John Nunemaker | July 29th, 2008 @ 09:42 PM

Somehow developers should be able to get at the response code or raise custom exceptions for given codes.

Comments and changes to this ticket

  • John Nunemaker

    John Nunemaker August 4th, 2008 @ 02:49 PM

    FYI: my thoughts on this are something like:

    handle_response 503, CustomException
    

    handle_response 400..404, DifferentException

    handle_response 404 do |response|

    ...

    end

    I'm open to other ideas if anyone has any.

  • franxxk

    franxxk August 12th, 2008 @ 04:48 AM

    Why not just throwing Net::Exception for all...

    except like i say elsewhere, i think that we can follow redirection for n times (follow_redirect n)

    My experiment:

    
          def send_request(method, path, options={})
    ...
            response       = http(uri).request(request)
    
    	case response
            when Net::HTTPSuccess     then
    		  parse_response(response.body)
            else
              response.error! # raises  exception corresponding to http error Net::XXX
            end
    
  • Milo

    Milo August 12th, 2008 @ 01:27 PM

    I would prefer to just get an exception as well. Here's what I did to send_request:

    
    if response.kind_of?(Net::HTTPSuccess)
      return parse_response(response.body)
    else
      response.instance_eval { class << self; attr_accessor :body_parsed; end }
      begin; response.body_parsed = parse_response(response.body); rescue; end
      response.error! # re-raise the exception
    end
    

    With this you can rescue the exception and get a parsed error message out of it as well with $!.response.body.

  • Milo

    Milo August 12th, 2008 @ 01:28 PM

    $!.response.body_parsed, I mean.

  • John Nunemaker

    John Nunemaker August 22nd, 2008 @ 10:09 PM

    • → State changed from “new” to “resolved”

    Went with the exception raising. Closed in http://github.com/jnunemaker/htt...>

Please Login or create a free account to add a new comment.

You can update this ticket by sending an email to from your email client. (help)

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

Tickets for the HTTParty ruby gem.

People watching this ticket