-
Notifications
You must be signed in to change notification settings - Fork 116
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
Handle Faraday::ServerError in Diplomat::Query#create #228
base: master
Are you sure you want to change the base?
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -256,7 +256,7 @@ def send_get_request(connection, url, options, custom_params = nil) | |
rest_options[:headers].map { |k, v| req.headers[k.to_sym] = v } unless rest_options[:headers].nil? | ||
req.options.timeout = options[:timeout] if options[:timeout] | ||
end | ||
rescue Faraday::ClientError, Faraday::ServerError => e | ||
rescue *faraday_error_classes => e | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This part of existing code sucks because it raises a Diplomat::PathNotFound in most cases, but users might rely on it... just rescue |
||
resp = e.response | ||
if resp | ||
raise Diplomat::AclNotFound, e if resp[:status] == 403 && resp[:body] == 'ACL not found' | ||
|
@@ -304,6 +304,14 @@ def send_delete_request(connection, url, options, custom_params = nil) | |
end | ||
end | ||
|
||
# This method returns the correct Exception Classes depending on the Faraday version being installed | ||
# see https://github.com/WeAreFarmGeek/diplomat/issues/227 | ||
# | ||
# @return [Array<Class>] Faraday error classes that should be caught | ||
def faraday_error_classes | ||
Faraday.const_defined?(:ServerError) ? [Faraday::ClientError, Faraday::ServerError] : [Faraday::ClientError] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hum, we probably misunderstood each other: My point was:
|
||
end | ||
Comment on lines
+313
to
+315
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not entirely sure about the name/placement of this method, but is this like what you had in mind? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Actually, i think it is bad to catch both ClientError and ServerError when ServerError exists, because it would thow a QueryAlreadyExists when a timeout occurs. So I would use your code, but only return ServerError in such case, not ClientError, to avoid code calling this that this query exist while it is just that the agent did timeout for instance. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hmm, |
||
|
||
# Mapping for valid key/value store transaction verbs and required parameters | ||
# | ||
# @return [Hash] valid key/store transaction verbs and required parameters | ||
|
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.
See my comment below on faraday_error_classes