Mechanize doesn't raise Mechanize::ResponseCodeError if error happened before getting the response #618
Replies: 4 comments
-
@adrianodennanni Thanks for opening this issue, this is a good conversation to have. The exception class 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. |
Beta Was this translation helpful? Give feedback.
-
I will paste here an example of this happening. The exception message for the A simple get, such as
In other occasions, the same |
Beta Was this translation helpful? Give feedback.
-
@adrianodennanni Again, 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. |
Beta Was this translation helpful? Give feedback.
-
This is illuminating. Is there any guidance to what networking exceptions we should handle? As a new user of this gem, I was kind of hoping rescuing |
Beta Was this translation helpful? Give feedback.
-
I was looking trough my logs of requests made with Mechanize and noticed that sometimes, a request might raise the default
Mechanize::ResponseCodeError
exception, but it would also raiseNet::HTTPFatalError
(500, 501, 502, 503) in the same line of code, at different times.This last error (
Net::HTTPFatalError
) is first generated during theconnection.request
in the following block insidemechanize/http/agent.rb.rb
:Since it happens before getting the response,
raise Mechanize::ResponseCodeError.new(page, 'unhandled response')
is never called, ending up with Mechanize raising theNet::HTTPFatalError
exception.I think it would be great if the only exception raised in this case was
Mechanize::ResponseCodeError
, since it should handle the errors that happened in the connection with the HTTP server, and not only handling the errors if the response exists.Beta Was this translation helpful? Give feedback.
All reactions