lib/httpx/response.rb in httpx-0.17.0 vs lib/httpx/response.rb in httpx-0.18.0
- old
+ new
@@ -55,23 +55,29 @@
end
# :nocov:
def inspect
"#<Response:#{object_id} "\
- "HTTP/#{version} " \
- "@status=#{@status} " \
- "@headers=#{@headers} " \
- "@body=#{@body.bytesize}>"
+ "HTTP/#{version} " \
+ "@status=#{@status} " \
+ "@headers=#{@headers} " \
+ "@body=#{@body.bytesize}>"
end
# :nocov:
- def raise_for_status
+ def error
return if @status < 400
- raise HTTPError, self
+ HTTPError.new(self)
end
+ def raise_for_status
+ return self unless (err = error)
+
+ raise err
+ end
+
def json(options = nil)
decode("json", options)
end
def form
@@ -209,22 +215,24 @@
@length = 0
@state = :closed
end
def ==(other)
- if other.respond_to?(:read)
- _with_same_buffer_pos { FileUtils.compare_stream(@buffer, other) }
- else
- to_s == other.to_s
+ object_id == other.object_id || begin
+ if other.respond_to?(:read)
+ _with_same_buffer_pos { FileUtils.compare_stream(@buffer, other) }
+ else
+ to_s == other.to_s
+ end
end
end
# :nocov:
def inspect
"#<HTTPX::Response::Body:#{object_id} " \
- "@state=#{@state} " \
- "@length=#{@length}>"
+ "@state=#{@state} " \
+ "@length=#{@length}>"
end
# :nocov:
private
@@ -309,20 +317,21 @@
@options = Options.new(options)
log_exception(@error)
end
def status
+ warn ":#{__method__} is deprecated, use :error.message instead"
@error.message
end
if Exception.method_defined?(:full_message)
def to_s
- @error.full_message
+ @error.full_message(highlight: false)
end
else
def to_s
"#{@error.message} (#{@error.class})\n" \
- "#{@error.backtrace.join("\n") if @error.backtrace}"
+ "#{@error.backtrace.join("\n") if @error.backtrace}"
end
end
def raise_for_status
raise @error