Skip to content

Commit e8b9e1c

Browse files
committed
Preserve ability to inherit from original error
#396 (comment)
1 parent f2d7d40 commit e8b9e1c

File tree

2 files changed

+8
-6
lines changed

2 files changed

+8
-6
lines changed

lib/active_resource/exceptions.rb

+1-6
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,7 @@ def to_s; @message ; end
3636
end
3737

3838
# Raised when a Errno::ECONNREFUSED occurs.
39-
class ConnectionRefusedError < ConnectionError
40-
def initialize(message)
41-
@message = message
42-
end
43-
def to_s; @message ; end
44-
end
39+
class ConnectionRefusedError < Errno::ECONNREFUSED; end
4540

4641
# 3xx Redirection
4742
class Redirection < ConnectionError # :nodoc:

test/cases/connection_test.rb

+7
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,13 @@ def test_handle_econnrefused
289289
assert_raise(ActiveResource::ConnectionRefusedError) { @conn.get("/people/1.json") }
290290
end
291291

292+
def test_handle_econnrefused_with_backwards_compatible_error
293+
http = Net::HTTP.new("")
294+
@conn.expects(:http).returns(http)
295+
http.expects(:get).raises(Errno::ECONNREFUSED, "Failed to open TCP connection")
296+
assert_raise(Errno::ECONNREFUSED) { @conn.get("/people/1.json") }
297+
end
298+
292299
def test_auth_type_can_be_string
293300
@conn.auth_type = "digest"
294301
assert_equal(:digest, @conn.auth_type)

0 commit comments

Comments
 (0)