Skip to content

Commit

Permalink
Preserve ability to inherit from original error
Browse files Browse the repository at this point in the history
  • Loading branch information
balvig committed Jan 29, 2024
1 parent f2d7d40 commit e8b9e1c
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
7 changes: 1 addition & 6 deletions lib/active_resource/exceptions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,7 @@ def to_s; @message ; end
end

# Raised when a Errno::ECONNREFUSED occurs.
class ConnectionRefusedError < ConnectionError
def initialize(message)
@message = message
end
def to_s; @message ; end
end
class ConnectionRefusedError < Errno::ECONNREFUSED; end

# 3xx Redirection
class Redirection < ConnectionError # :nodoc:
Expand Down
7 changes: 7 additions & 0 deletions test/cases/connection_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,13 @@ def test_handle_econnrefused
assert_raise(ActiveResource::ConnectionRefusedError) { @conn.get("/people/1.json") }
end

def test_handle_econnrefused_with_backwards_compatible_error
http = Net::HTTP.new("")
@conn.expects(:http).returns(http)
http.expects(:get).raises(Errno::ECONNREFUSED, "Failed to open TCP connection")
assert_raise(Errno::ECONNREFUSED) { @conn.get("/people/1.json") }
end

def test_auth_type_can_be_string
@conn.auth_type = "digest"
assert_equal(:digest, @conn.auth_type)
Expand Down

0 comments on commit e8b9e1c

Please sign in to comment.