class HTTPX::ErrorResponse

  1. lib/httpx/response.rb
Superclass: Object

Wraps an error which has happened while processing an HTTP Request. It has partial public API parity with HTTPX::Response, so users should rely on it to infer whether the returned response is one or the other.

response = HTTPX.get("https://some-domain/path") #=> response is HTTPX::Response or HTTPX::ErrorResponse
response.raise_for_status #=> raises if it wraps an error

Methods

Public Class

  1. new

Public Instance

  1. <<
  2. close
  3. error
  4. finish!
  5. finished?
  6. raise_for_status
  7. request
  8. response
  9. to_s

Attributes

error [R]

the wrapped exception.

request [R]

the corresponding HTTPX::Request instance.

response [R]

the HTTPX::Response instance, when there is one (i.e. error happens fetching the response).

Public Class methods

new(request, error)
[show source]
    # File lib/httpx/response.rb
287 def initialize(request, error)
288   @request = request
289   @response = request.response if request.response.is_a?(Response)
290   @error = error
291   @options = request.options
292   @request.log_exception(@error)
293   finish!
294 end

Public Instance methods

<<(data)

buffers lost chunks to error response

[show source]
    # File lib/httpx/response.rb
321 def <<(data)
322   return unless @response
323 
324   @response << data
325 end
close()

closes the error resources.

[show source]
    # File lib/httpx/response.rb
302 def close
303   @response.close if @response
304 end
finish!()
[show source]
    # File lib/httpx/response.rb
311 def finish!
312   @request.connection = nil
313 end
finished?()

always true for error responses.

[show source]
    # File lib/httpx/response.rb
307 def finished?
308   true
309 end
raise_for_status()

raises the wrapped exception.

[show source]
    # File lib/httpx/response.rb
316 def raise_for_status
317   raise @error
318 end
to_s()

returns the exception full message.

[show source]
    # File lib/httpx/response.rb
297 def to_s
298   @error.full_message(highlight: false)
299 end