diff --git a/lib/net/http/response.rb b/lib/net/http/response.rb index e2964c41a1..1351d7b2d2 100644 --- a/lib/net/http/response.rb +++ b/lib/net/http/response.rb @@ -117,7 +117,9 @@ class Net::HTTPResponse end def error! #:nodoc: - raise error_type().new(@code + ' ' + @message.dump, self) + message = @code + message += ' ' + @message.dump if @message + raise error_type().new(message, self) end def error_type #:nodoc: diff --git a/test/net/http/test_httpresponse.rb b/test/net/http/test_httpresponse.rb index a494b7fb85..a67add7c88 100644 --- a/test/net/http/test_httpresponse.rb +++ b/test/net/http/test_httpresponse.rb @@ -385,6 +385,22 @@ EOS assert_equal(nil, res.message) end + def test_raises_exception_with_missing_reason + io = dummy_io(<