-
Notifications
You must be signed in to change notification settings - Fork 321
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow Features to handle connection errors #552
Conversation
4f9756c
to
c02c0cb
Compare
This mirrors httprb#552, which has not been merged yet
c02c0cb
to
0df981e
Compare
This mirrors httprb#552, which has not been merged yet
Looks like you need to fix the RuboCop errors. Otherwise conceptually this seems ok to me. @ixti what do you think? |
@paul any thoughts on this approach, or suggested alternatives? |
@tarcieri No, this seems fine to me. 👍 |
lib/http/client.rb
Outdated
@connection.read_headers! | ||
end | ||
rescue Error => e | ||
options.features.each do |_name, feature| |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you can do each_value
here (and potentially collapse it into a 1-liner), e.g.:
options.features.each_value { |feature| feature.on_error(req, e) }
It is difficult as an outside contributor to understand which rubocop rules a team cares about. Were each of the rules chosen because they are what the team values? Or were they just the defaults? For example, this project currently has the
Is it really appropriate for this PR to take on the task of refactoring the Or should I disable the rule? Or just exclude this file? Or just exclude this method? |
It's explicitly configured to 25 lines in
If you really don't want to refactor it you can disable the check for this method in particular using That said it looks like |
I don't mind doing the refactor, I just thought it was out of scope for this task, and would obscure the point of this PR. I'll go ahead and disable the rule here, and leave it as a follow up issue. |
What if error will happen down the course, e.g. during response streaming? |
@ixti it seems like under this approach features wouldn't be able to handle those errors, however it seems like they can handle the most interesting errors, i.e. immediate response errors |
0df981e
to
45fb8c0
Compare
I have rebased and addressed the rubocop issues. |
Thank you! I have taken another look, and I think we can make API a bit more "flexible" if we will rename def observe(event, data); end
# ...
options.features.each_value { |f| f.observe(:request_error, :req => self, :err => e) } Just an idea. As I don't like |
@ixti what about |
I think that could be a good idea if you know of other events that would make sense to observe. |
Yeah. I think And I agree, that def on_request(req:); end
def on_request_error(req:, err:); end
def on_response(res:); end
def on_response_error(res:, err:); end So that it will be absolutely obvious which kwargs will be passed. |
Can we move forward with this PR and leave the |
@joshuaflanagan that sounds fine to me |
Done |
@joshuaflanagan this one now has a conflict |
This addresses httprb#547 It allows a Feature to implement an on_error handler so that it has a chance to react to Requests that never get a Response. > Extracted the build_response method to stay under the rubocop enforced method length limit.
45fb8c0
to
197178b
Compare
@ixti let me know if you have any qualms about landing this. We can potentially explore alternatives before cutting another release |
This addresses #547
It allows a Feature to implement an on_error handler so that it has a chance to react to Requests that never get a Response.