Class: HTTPX::ErrorResponse
- Inherits:
-
Object
- Object
- HTTPX::ErrorResponse
- Extended by:
- Forwardable
- Includes:
- _Reader, ErrorResponsePatternMatchExtensions, Loggable, _Response
- Defined in:
- lib/httpx/response.rb,
sig/response.rbs
Overview
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
Constant Summary
Constants included from Loggable
Loggable::COLORS, Loggable::USE_DEBUG_LOG
Instance Attribute Summary collapse
-
#error ⇒ Object
readonly
the wrapped exception.
-
#request ⇒ Object
readonly
the corresponding HTTPX::Request instance.
-
#response ⇒ Object
readonly
the HTTPX::Response instance, when there is one (i.e. error happens fetching the response).
Instance Method Summary collapse
-
#<<(data) ⇒ Object
buffers lost chunks to error response.
-
#close ⇒ void
closes the error resources.
- #finish! ⇒ Object
-
#finished? ⇒ Boolean
always true for error responses.
- #peer_address ⇒ String, ...
-
#raise_for_status ⇒ Object
raises the wrapped exception.
- #status ⇒ Integer, _ToS
-
#to_s ⇒ Object
returns the exception full message.
- #uri ⇒ URI::Generic
Methods included from ErrorResponsePatternMatchExtensions
#deconstruct, #deconstruct_keys
Methods included from Loggable
#log, #log_exception, log_identifiers
Instance Attribute Details
#error ⇒ Object (readonly)
the wrapped exception.
291 292 293 |
# File 'lib/httpx/response.rb', line 291 def error @error end |
#request ⇒ Object (readonly)
the corresponding HTTPX::Request instance.
285 286 287 |
# File 'lib/httpx/response.rb', line 285 def request @request end |
#response ⇒ Object (readonly)
the HTTPX::Response instance, when there is one (i.e. error happens fetching the response).
288 289 290 |
# File 'lib/httpx/response.rb', line 288 def response @response end |
Instance Method Details
#<<(data) ⇒ Object
buffers lost chunks to error response
333 334 335 336 337 |
# File 'lib/httpx/response.rb', line 333 def <<(data) return unless @response @response << data end |
#close ⇒ void
This method returns an undefined value.
closes the error resources.
314 315 316 |
# File 'lib/httpx/response.rb', line 314 def close @response.close if @response end |
#finish! ⇒ Object
323 324 325 |
# File 'lib/httpx/response.rb', line 323 def finish! @request.connection = nil end |
#finished? ⇒ Boolean
always true for error responses.
319 320 321 |
# File 'lib/httpx/response.rb', line 319 def finished? true end |
#peer_address ⇒ String, ...
98 |
# File 'sig/response.rbs', line 98
def peer_address: () -> (String | IPAddr)?
|
#raise_for_status ⇒ Object
raises the wrapped exception.
328 329 330 |
# File 'lib/httpx/response.rb', line 328 def raise_for_status raise @error end |
#status ⇒ Integer, _ToS
94 |
# File 'sig/response.rbs', line 94
def status: () -> (Integer | _ToS)
|
#to_s ⇒ Object
returns the exception full message.
309 310 311 |
# File 'lib/httpx/response.rb', line 309 def to_s @error.(highlight: false) end |
#uri ⇒ URI::Generic
96 |
# File 'sig/response.rbs', line 96
def uri: () -> URI::Generic
|