diff --git a/lib/requests.rb b/lib/requests.rb index 74a697d..4ce1711 100644 --- a/lib/requests.rb +++ b/lib/requests.rb @@ -5,12 +5,15 @@ module Requests class Error < StandardError - attr_reader :response + attr_reader :response, :status, :headers, :body def initialize(response) super(response.message) @response = response + @status = Integer(response.code) + @headers = response.to_hash + @body = response.body end end diff --git a/tests/proxy_test.rb b/tests/proxy_test.rb index 0acb364..19551a2 100644 --- a/tests/proxy_test.rb +++ b/tests/proxy_test.rb @@ -26,7 +26,7 @@ assert_equal ['application/json'], r.headers['content-type'] assert(r.json['args'] && r.json['args']['foo'] == 'bar') - assert_equal ["1.1 vegur, 1.1 0.0.0.0:#{port}"], r.headers['via'] + assert_equal ["1.1 0.0.0.0:#{port}"], r.headers['via'] proxy.shutdown end diff --git a/tests/requests_test.rb b/tests/requests_test.rb index a15a39b..85bab4a 100644 --- a/tests/requests_test.rb +++ b/tests/requests_test.rb @@ -55,6 +55,10 @@ Requests.post('http://httpbin.org/something') rescue Requests::Error => e assert_equal Net::HTTPNotFound, e.response.class + + assert_equal Hash, e.headers.class + assert_equal String, e.body.class + assert_equal 404, e.status end end