Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hide implementation details #261

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions lib/http/connection.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ def initialize(req, options)
send_proxy_connect_request(req)
start_tls(req, options)
reset_timer

rescue SocketError, SystemCallError => ex
raise HTTP::Error.new(ex)
end

# @see (HTTP::Response::Parser#status_code)
Expand Down
3 changes: 3 additions & 0 deletions lib/http/errors.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,7 @@ class TimeoutError < Error; end

# Header name is invalid
class InvalidHeaderNameError < Error; end

# Something unexpected happened, probably a bug
class UnexpectedError < Error;end
end
1 change: 1 addition & 0 deletions lib/http/response/status.rb
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ def #{symbol}? # def bad_request?
end

def __setobj__(obj)
raise HTTP::UnexpectedError.new('expected object to respond_to #to_i') unless obj.respond_to?(:to_i)
@code = obj.to_i
end

Expand Down
6 changes: 3 additions & 3 deletions spec/lib/http/request/writer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
let(:body) { 123 }

it "raises an error" do
expect { writer }.to raise_error
expect { writer }.to raise_error(HTTP::RequestError)
end
end
end
Expand All @@ -59,12 +59,12 @@

context "when Transfer-Encoding not set" do
let(:headers) { HTTP::Headers.new }
specify { expect { writer.stream }.to raise_error }
specify { expect { writer.stream }.to raise_error(HTTP::RequestError) }
end

context "when Transfer-Encoding is not chunked" do
let(:headers) { HTTP::Headers.coerce "Transfer-Encoding" => "gzip" }
specify { expect { writer.stream }.to raise_error }
specify { expect { writer.stream }.to raise_error(HTTP::RequestError) }
end
end

Expand Down
2 changes: 1 addition & 1 deletion spec/lib/http/response/status_spec.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
RSpec.describe HTTP::Response::Status do
describe ".new" do
it "fails if given value does not respond to #to_i" do
expect { described_class.new double }.to raise_error
expect { described_class.new double }.to raise_error(HTTP::UnexpectedError)
end

it "accepts any object that responds to #to_i" do
Expand Down
5 changes: 5 additions & 0 deletions spec/lib/http_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -337,5 +337,10 @@
client = HTTP.headers("Cookie" => "foo=bar").cookies(:baz => :moo)
expect(client.get(endpoint).to_s).to eq "foo: bar\nbaz: moo"
end

it "throws correct error" do
expect { HTTP.get('http://thishostshouldnotexists.com') }.to raise_error(HTTP::Error)
expect { HTTP.get('http://127.0.0.1:000') }.to raise_error(HTTP::Error)
end
end
end