Skip to content

Commit

Permalink
Merge pull request #309 from github/make-faraday-upgrade-compatible
Browse files Browse the repository at this point in the history
Replace Faraday::Error::* usage
  • Loading branch information
jasonkim authored Apr 10, 2024
2 parents 5d9cc37 + 173991d commit 791a473
Show file tree
Hide file tree
Showing 9 changed files with 19 additions and 24 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
## 6.1.0 (2024-04-09)
- Replace `Faraday::Error::*` with `Faraday::*` error classes
- Handle all `Faraday::Error` instead of `Faraday::Error::ClientError`
- Unlock faraday version to allow 1.0.0
- Bump the minimum version of faraday and faraday middleware

## 6.0.3 (2024-04-05)
- Add ES 8.13 REST API spec
- Update CI and development versions from 8.7.0 to 8.13.0
Expand Down
4 changes: 2 additions & 2 deletions elastomer-client.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ Gem::Specification.new do |spec|
spec.require_paths = ["lib"]

spec.add_dependency "addressable", "~> 2.5"
spec.add_dependency "faraday", "~> 0.8"
spec.add_dependency "faraday_middleware", "~> 0.12"
spec.add_dependency "faraday", ">= 0.17"
spec.add_dependency "faraday_middleware", "~> 0.14"
spec.add_dependency "multi_json", "~> 1.12"
spec.add_dependency "semantic", "~> 1.6"
end
2 changes: 1 addition & 1 deletion lib/elastomer_client/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ def request(method, path, params)
handle_errors response

# wrap Faraday errors with appropriate ElastomerClient::Client error classes
rescue Faraday::Error::ClientError => boom
rescue Faraday::Error => boom
error = wrap_faraday_error(boom, method, path)
raise error
rescue OpaqueIdError => boom
Expand Down
11 changes: 0 additions & 11 deletions lib/elastomer_client/client/errors.rb
Original file line number Diff line number Diff line change
Expand Up @@ -97,17 +97,6 @@ def fatal
ConnectionFailed.fatal = false
RejectedExecutionError.fatal = false

# Define an ElastomerClient::Client exception class on the fly for
# Faraday exception classes that we don't specifically wrap.
Faraday::Error.constants.each do |error_name|
next if ::ElastomerClient::Client.const_get(error_name) rescue nil

error_class = Faraday::Error.const_get(error_name)
next unless error_class < Faraday::Error::ClientError

::ElastomerClient::Client.const_set(error_name, Class.new(Error))
end

# Exception for operations that are unsupported with the version of
# Elasticsearch being used.
IncompatibleVersionException = Class.new Error
Expand Down
2 changes: 1 addition & 1 deletion lib/elastomer_client/middleware/parse_json.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def call(environment)
def parse(body)
MultiJson.load(body) if body.respond_to?(:to_str) && !body.strip.empty?
rescue StandardError, SyntaxError => e
raise Faraday::Error::ParsingError, e
raise Faraday::ParsingError, e
end

def process_response?(env)
Expand Down
2 changes: 1 addition & 1 deletion lib/elastomer_client/version.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# frozen_string_literal: true

module ElastomerClient
VERSION = "6.0.3"
VERSION = "6.1.0"

def self.version
VERSION
Expand Down
2 changes: 1 addition & 1 deletion test/client/errors_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
end

it "is instantiated from another exception" do
err = Faraday::Error::ConnectionFailed.new "could not connect to host"
err = Faraday::ConnectionFailed.new "could not connect to host"
err.set_backtrace %w[one two three four]

err = ElastomerClient::Client::Error.new(err, "POST", "/index/doc")
Expand Down
12 changes: 6 additions & 6 deletions test/middleware/parse_json_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,14 @@ def process(body, content_type = nil)
end

it "chokes on invalid json" do
assert_raises(Faraday::Error::ParsingError) { process "{!" }
assert_raises(Faraday::Error::ParsingError) { process "invalid" }
assert_raises(Faraday::ParsingError) { process "{!" }
assert_raises(Faraday::ParsingError) { process "invalid" }

# surprisingly these are all valid according to MultiJson
#
# assert_raises(Faraday::Error::ParsingError) { process '"a"' }
# assert_raises(Faraday::Error::ParsingError) { process 'true' }
# assert_raises(Faraday::Error::ParsingError) { process 'null' }
# assert_raises(Faraday::Error::ParsingError) { process '1' }
# assert_raises(Faraday::ParsingError) { process '"a"' }
# assert_raises(Faraday::ParsingError) { process 'true' }
# assert_raises(Faraday::ParsingError) { process 'null' }
# assert_raises(Faraday::ParsingError) { process '1' }
end
end
2 changes: 1 addition & 1 deletion test/notifications_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
end

it "instruments timeouts" do
$client.stub :connection, lambda { raise Faraday::Error::TimeoutError } do
$client.stub :connection, lambda { raise Faraday::TimeoutError } do
assert_raises(ElastomerClient::Client::TimeoutError) { $client.info }
event = @events.detect { |e| e.payload[:action] == "cluster.info" }
exception = event.payload[:exception]
Expand Down

0 comments on commit 791a473

Please sign in to comment.