Skip to content

Commit

Permalink
Refactor Excon errors
Browse files Browse the repository at this point in the history
  • Loading branch information
hakanensari committed Jul 8, 2016
1 parent 7e420b9 commit ed39dc7
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 10 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ Alternatively, rescue.
```ruby
begin
client.some_method
rescue Excon::Errors::ServiceUnavailable => e
rescue Excon::Error::ServiceUnavailable => e
logger.warn e.response.message
retry
end
Expand Down
8 changes: 4 additions & 4 deletions lib/peddler/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def version(version = nil)
end

# Sets an error handler
# @yieldparam [Excon::Errors::Error] error
# @yieldparam [Excon::Error] error
def on_error(&blk)
@error_handler = blk
end
Expand Down Expand Up @@ -149,7 +149,7 @@ def headers
end

# Sets an error handler
# @yieldparam [Excon::Errors::Error] error
# @yieldparam [Excon::Error] error
def on_error(&blk)
@error_handler = blk
end
Expand All @@ -171,7 +171,7 @@ def run
res = post(opts)

parser.new(res, encoding)
rescue Excon::Errors::Error => e
rescue Excon::Error => e
handle_error(e)
end

Expand Down Expand Up @@ -208,7 +208,7 @@ def handle_error(e)
end

def decorate_error(e)
if e.is_a?(::Excon::Errors::HTTPStatusError)
if e.is_a?(:: Excon::Error::HTTPStatus)
e.instance_variable_set(:@response, Errors::Parser.new(e.response))
end

Expand Down
2 changes: 1 addition & 1 deletion lib/peddler/errors/handler.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def error_class
end

def http_status_error?
exception.is_a?(Excon::Errors::HTTPStatusError)
exception.is_a?(Excon::Error::HTTPStatus)
end
end
end
Expand Down
1 change: 1 addition & 0 deletions peddler.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ Gem::Specification.new do |gem|
gem.test_files = Dir.glob('test/**/*')
gem.require_paths = ['lib']

gem.add_dependency 'excon', '>= 0.50.0'
gem.add_dependency 'jeff', '~> 1.3'
gem.add_dependency 'multi_xml', '~> 0.5.0'
gem.required_ruby_version = '>= 2.0'
Expand Down
2 changes: 1 addition & 1 deletion test/unit/peddler/errors/test_handler.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class CausedByHTTPStatusError < TestPeddlerErrorsHandler
def setup
@code = 'FeedProcessingResultNotReady'
@message = 'Feed Submission Result is not ready for Feed 123'
@cause = Excon::Errors::NotFound.new(
@cause = Excon::Error::NotFound.new(
'Expected(200) <=> Actual(404 Not Found)',
nil,
OpenStruct.new(code: @code, message: @message)
Expand Down
6 changes: 3 additions & 3 deletions test/unit/peddler/test_client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ def test_request_preserves_user_agent
def test_error_callback_on_class
Excon.stub({}, status: 503)

assert_raises(Excon::Errors::ServiceUnavailable) do
assert_raises(Excon::Error::ServiceUnavailable) do
@client.run
end

Expand All @@ -153,7 +153,7 @@ def test_error_callback_on_class
def test_error_callback_on_instance
Excon.stub({}, status: 503)

assert_raises(Excon::Errors::ServiceUnavailable) do
assert_raises(Excon::Error::ServiceUnavailable) do
@client.run
end

Expand All @@ -177,7 +177,7 @@ def test_error_callback_on_client_ancestor
other_client = klass.new
other_client.configure_with_mock_data!
other_client.operation('Foo')
assert_raises(Excon::Errors::ServiceUnavailable) do
assert_raises(Excon::Error::ServiceUnavailable) do
other_client.run
end

Expand Down

0 comments on commit ed39dc7

Please sign in to comment.