lib/httpx/response.rb in httpx-0.0.2 vs lib/httpx/response.rb in httpx-0.0.3

- old
+ new

@@ -58,10 +58,15 @@ def inspect "#<Response:#{object_id} @status=#{@status} @headers=#{@headers}>" end + def raise_for_status + return if @status < 400 + raise HTTPError, @status + end + class Body def initialize(response, threshold_size:, window_size: 1 << 14) @response = response @headers = response.headers @threshold_size = threshold_size @@ -207,16 +212,27 @@ end end end class ErrorResponse + include Loggable + attr_reader :error, :retries - alias_method :status, :error - - def initialize(error, retries) + def initialize(error, retries, options) @error = error @retries = retries + @options = Options.new(options) + log { "#{error.class}: #{error}" } + log { caller.join("\n") } + end + + def status + @error.message + end + + def raise_for_status + raise @error end def retryable? @retries.positive? end