Git Product home page Git Product logo

Comments (3)

flavorjones avatar flavorjones commented on July 19, 2024

@adrianodennanni Thanks for opening this issue, this is a good conversation to have.

The exception class Mechanize::ResponseCodeError is intended to wrap up a successful response from the server that has an HTTP status code other than 200, 301, or 302.

In the case you're describing, are you saying that you received a response from the server that was a 50x status code? Or was this a networking error? I'm a little confused by the string "(500, 501, 502, 503)" in the description.

from mechanize.

adrianodennanni avatar adrianodennanni commented on July 19, 2024

I will paste here an example of this happening.

The exception message for the Net::HTTPFatalError was 503 "Service Unavailable".

A simple get, such as agent.get 'https://example.com' raised me Net::HTTPFatalError, with the following trace:

503 "Service Unavailable" (Net::HTTPFatalError)
/usr/local/lib/ruby/3.2.0/net/http/response.rb:258:in `error!'
/usr/local/lib/ruby/3.2.0/net/http/response.rb:267:in `value'
/usr/local/lib/ruby/3.2.0/net/http.rb:1293:in `connect'
/usr/local/lib/ruby/3.2.0/net/http.rb:1248:in `do_start'
/usr/local/lib/ruby/3.2.0/net/http.rb:1243:in `start'
/usr/local/bundle/gems/net-http-persistent-4.0.1/lib/net/http/persistent.rb:655:in `start'
/usr/local/bundle/gems/net-http-persistent-4.0.1/lib/net/http/persistent.rb:595:in `connection_for'
/usr/local/bundle/gems/net-http-persistent-4.0.1/lib/net/http/persistent.rb:885:in `request'
/usr/local/bundle/gems/mechanize-2.8.5/lib/mechanize/http/agent.rb:284:in `fetch'
/usr/local/bundle/gems/mechanize-2.8.5/lib/mechanize.rb:465:in `get'
/app/domain/my_example_script.rb:35:in `get_page'

In other occasions, the same agent.get line raised me a normal Mechanize::ResponseCodeError. I believe this case happened when response was completed, while the the previously mentioned exception happened during the connection phase of the fetch.

from mechanize.

flavorjones avatar flavorjones commented on July 19, 2024

@adrianodennanni Again, ResponseCodeError is only intended to be used when a response has been successfully read, and the status code is surprising.

An exception related to networking should not be rescued by Mechanize -- in this case, the exception raised by Net::HTTP is what is raised. I think this is behaving as intended.

I'm happy to continue the conversation if you like -- I'm going to convert it to a Discussion.

from mechanize.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.